简体   繁体   中英

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. The rectangle of the textbox keeps blinking. I can't select it or do anything.

The view class is inherented from CView. The info. i got from research is that CEdit usually added to dialog class, but i can still add it to any view.

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. In fact, unless your view contains something else you need to draw, you may not need to handle OnDraw at all.

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).

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.
  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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