Detect key "Enter" in textBox

I hope to make something like this:
In a form and only one text box in it
User can type things in the text box
When user press "Enter" that key in keyboard
It has a pop up message comes up and show what has the user typed in the text box

All i can do now is have an extra button for it
but I think it is so user unfriendly
I don't know how to check if user press "Enter" that key in the text box
Please help
Check out ES_WANTRETURN here: http://msdn.microsoft.com/en-us/library/windows/desktop/bb775464%28v=vs.85%29.aspx

Once the edit control is accepting Enter, you can process keys as they're typed and check for that character.
I almost dead from reading that.....
But after all, i don't know how to use it
Like where and how should i put it in the code
Pass ES_WANTRETURN and ES_MULTILINE to style parameter or CreateWindow (Ex) or use SetWindowLongPtr aftewards, it has the same effect.

You need to subclass the edit control and handle WM_KEYDOWN message. If it's the key you want, send the message, otherwise, let the default edit control procedure do its job.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
WNDPROC oldEditProc;

LRESULT CALLBACK subEditProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
   switch (msg)
   {
    case WM_KEYDOWN:
         switch (wParam)
         {
          case VK_RETURN:
          //Do your stuff
              break;  //or return 0; if you don't want to pass it further to def proc
          //If not your key, skip to default:
         }
    default:
         return CallWindowProc(oldEditProc, wnd, msg, wParam, lParam);
   }
   return 0;
}

void somecreateeditproc()
{
  HWND hInput = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", 
    WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL, 
    0, 0, 100, 100, hwnd, (HMENU)IDC_MAIN_INPUT, GetModuleHandle(NULL), NULL);

  oldEditProc = (WNDPROC)SetWindowLongPtr(hInput, GWLP_WNDPROC, (LONG_PTR)subEditProc);
}



If you are using winforms crap (and by the words "form" and "textbox" I think you do) then I guess you are out of luck :)
You have to specify ES_WANTRETURN so the edit control input doesn't terminate.

As you enter keys into the edit control, it notifies you with EN_CHANGE and EN_UPDATE. These allow you to intercept the keys before or after they are displayed.
http://msdn.microsoft.com/en-us/library/windows/desktop/ff485924%28v=vs.85%29.aspx

You handle the appropriate notification and check for ENTER.

Got it?
Topic archived. No new replies allowed.