WM_KEYUP event not working.... RRS feed

  • Question

  • I want to get extended key (i.e. Enter, Shift, Del etc) pressed in the EditBox. I have added

    WM_KEYUP event for that but that event is not called. I don't know why?  I don't want to create sub-class of

    Edit. Can anybody let me know what can be the problem?

    My method is:

    void CTest_WinDlg::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
     // TODO: Add your message handler code here and/or call default
     MessageBox("Key up called.....");
     CDialog::OnKeyUp(nChar, nRepCnt, nFlags);

    Tuesday, December 5, 2006 12:13 AM


  • Did you add a ON_WM_KEYUP entry into your dialog's message map? If so and it doesn't fire that means the edit control eats those messages and you'll have to subclass the edit box to catch them. Or I guess you could override your Dialog class's PreTranslateMessage and check each message for WM_KEYUP and the edit box being the target...

    BOOL CMyDialog::PreTranslateMessage( MSG* pMsg)
    { if( pMsg->message == WM_KEYUP)
      { if( pMsg->hwnd == GetDlgItem( IDC_EDIT_BOX)->m_hWnd)
        { // key pressed in edit box pMsg members have the info you want.
      return CDialog::PreTranslateMessage( pMsg);

    I think that messages processed already by the app class's PreTranslateMessage, TranslateMessage, and DispatchMessage functions will not be routed thru the dialog's PreTranslateMessage function. Like if you press F1 and there is a message hook in the app class to make the help go, then you won't get the WM_KEYUP message in the dialog class for the VK_F1 key, but you will for other unused ones lik the VK_F3. In that case, you can override the CWinApp's PreTranslateMessage function instead to catch those before they get routed.


    Tuesday, December 5, 2006 12:33 AM