简体   繁体   English

MFC CEdit不会接受键盘输入

[英]MFC CEdit won't take keyboard input

I have a legacy project where i need to add a multi-line text box to the view. 我有一个旧项目,需要在视图中添加多行文本框。

I first simply want to create a textbox in onDraw function in my view class to put a text box on screen. 我首先只是想在我的视图类的onDraw函数中创建一个文本框,以在屏幕上放置一个文本框。 The rectangle of the textbox keeps blinking. 文本框的矩形一直闪烁。 I can't select it or do anything. 我无法选择它或执行任何操作。

The view class is inherented from CView. 视图类是CView固有的。 The info. 该信息。 i got from research is that CEdit usually added to dialog class, but i can still add it to any view. 我从研究中得到的是CEdit通常添加到对话框类,但是我仍然可以将其添加到任何视图。

CRect rect(100, 100, 300, 200);
CEdit test;
test.Create(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | ES_MULTILINE | WS_VSCROLL, \
    rect, this, 1);

I'm totally new to this, and before i get into all the handle and messaging, i just want to simply create a text box and type some text in it. 我对此完全陌生,在我进入所有句柄和消息传递之前,我只想简单地创建一个文本框并在其中输入一些文本即可。

Thank you for the help in advance. 谢谢您的帮助。

You probably don't want to create the edit control in your OnDraw. 您可能不想在OnDraw中创建编辑控件。 In fact, unless your view contains something else you need to draw, you may not need to handle OnDraw at all. 实际上,除非您的视图包含其他需要绘制的内容,否则可能根本不需要处理OnDraw。

When you have a view hosting a control, you usually want to create that control in the view's OnCreate, so it's created after the view's own window is created (which will be the control's parent) but before the view's window is displayed (so the control can be displayed at the same time). 当您拥有一个托管控件的视图时,通常希望在视图的OnCreate中创建该控件,因此它是在创建视图自己的窗口(将成为控件的父窗口)之后但在显示视图窗口之前创建的(因此控件可以同时显示)。

In this case, the view probably won't need to deal with drawing at all. 在这种情况下,视图可能根本不需要处理绘图。 It probably will need to deal with: 它可能需要处理:

  1. sizing: resize the control to fit the new size of the view's client area. 调整大小:调整控件的大小以适合视图客户区的新大小。
  2. focus: when the view receives focus, immediately give focus to the control. focus:当视图获得焦点时,立即将焦点赋予控件。
  3. Commands: you pretty routinely want to deal with things like: 命令:您通常想要处理类似以下内容的命令:
    • cut/copy/paste to/from the control 从控件剪切/复制/粘贴
    • put data into the control (eg, from a file) 将数据放入控件中(例如,来自文件)
    • get data out of the control (eg, save to a file) 从控件中获取数据(例如,保存到文件)
    • set the control's font 设置控件的字体

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM