title: Win32 API: How to catch escape key in Edit control?
body: <p>I found that for some unknown reason when focus is in <em>Edit control</em>, the Escape key never produces a messages.
  Below is a code to create a parent window, and <em>Edit control</em> above it. In <em>MyCallBckProcedure()</em> I laid <em>printf()</em> under a *WM_COMMAND*, to catch a messages, produced by <em>Edit</em>. More over -- I even tried to print all the messages catched in <em>MyCallBckProcedure()</em>; but if focus on <em>Edit</em>, the escape key never produces any of messages.
  What a weird problem could be here?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;windows.h&gt;
  #include &lt;stdio.h&gt;
  
  #define IDC_MAIN_EDIT 101
  
  LRESULT __stdcall MyCallBckProcedure( HWND window, unsigned msg, WPARAM wp, LPARAM lp ){
      printf("%x ",msg);
      switch(msg){
          case WM_COMMAND://here should be catched the escape key of Edit
              printf("%x ",msg);
              break;
          case WM_KEYDOWN:
              printf("%x ",msg);
              if(wp == VK_ESCAPE)PostQuitMessage(0);
              break;
          case WM_DESTROY:
              std::cout &lt;&lt; "\ndestroying window\n" ;
              PostQuitMessage(0);
              return 0;
          default:
              return DefWindowProc( window, msg, wp, lp ) ;
  
          break;
          case WM_SIZE:{
              HWND hEdit;
              RECT rcClient;
  
              GetClientRect(window, &amp;rcClient);
  
              hEdit = GetDlgItem(window, IDC_MAIN_EDIT);
              SetWindowPos(hEdit, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER);
          }
          break;
      }
  }
  
  int main(){
      const char* const myclass = "myclass";
      WNDCLASSEX wndclass = { sizeof(WNDCLASSEX), CS_DBLCLKS, MyCallBckProcedure,
                              0, 0, GetModuleHandle(0), LoadIcon(0,IDI_APPLICATION),
                              LoadCursor(0,IDC_ARROW), HBRUSH(COLOR_WINDOW+1),
                              0, myclass, LoadIcon(0,IDI_APPLICATION) };
      if(RegisterClassEx(&amp;wndclass)&lt;0){
          printf("ERR: in registering window class\n");
          return 1;
      }
      //Creating window
      HWND window = CreateWindowEx( 0, myclass, "title",
                     WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
                     CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, GetModuleHandle(0), 0 );
      if(!window){
          printf("ERR: in creating window\n");
          return 1;
      }
      ShowWindow( window, SW_SHOWDEFAULT );
      MSG msg;
      //creating TextBox on the window
      HFONT hfDefault;
      HWND hEdit;
      hEdit = CreateWindowEx(0, "edit", "", 
          WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL, 
          CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
          window, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);
      if(hEdit == NULL){
          MessageBox(window, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);
          return 1;
      }
      hfDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
      SendMessage(hEdit, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
      //Now resize TextBox to fill whole parent window
      RECT RectSize;
      GetClientRect(window,&amp;RectSize);
      hEdit = GetDlgItem(window,IDC_MAIN_EDIT);
      SetWindowPos(hEdit, 0,0,0,RectSize.right,RectSize.bottom,SWP_NOZORDER);
      //Process messages
      while(GetMessage(&amp;msg,0,0,0) ){
          TranslateMessage(&amp;msg);
          DispatchMessage(&amp;msg);
      }
  }
  </code></pre>