Detect keypress in dialog-based 
Author Message
 Detect keypress in dialog-based

Hi all,

I added the functions OnChar, OnKeyDown for catching the keypress
message in a dialog. However, it seems that the functions have no
response for the key press. Anybody knows why?

Thanks in advanced. : )



Mon, 01 Oct 2001 03:00:00 GMT  
 Detect keypress in dialog-based
Those messages get handled by the dialog within the bowels of the
PreTranslateMessage() function.  If you want to handle specific keys you
should override PreTranslateMessage like so:

BOOL
CMyDlg::PreTranslateMessage(MSG* pMsg)
{
BOOL bResult;

    switch(pMsg->message)
    {
        case WM_CHAR:
        case WM_KEYDOWN:
            switch(pMsg->wParam)
            {
                case VK_whatever:
                    TranslateMessage(pMsg); // may not be necessary -
depends on the key
                    DispatchMessage(pMsg);
                    bResult = TRUE;
                    break;

                default:
                    bResult = CDialog::PreTranslateMessage(pMsg);
            }
            break;

        default:
            bResult = CDialog::PreTranslateMessage(pMsg);
    }
    return bResult;

Quote:
}



Quote:
> Hi all,

> I added the functions OnChar, OnKeyDown for catching the keypress
> message in a dialog. However, it seems that the functions have no
> response for the key press. Anybody knows why?

> Thanks in advanced. : )



Mon, 01 Oct 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Detect when dialog-based app is minimized?

2. Detecting A Keypress

3. Detecting keypress

4. HELP! Keypress detect

5. Detecting a keypress

6. How To Detect KeyPress.

7. Detecting keypress when the focus is on CButton

8. HOW TO: detect a keypress

9. Detecting delete keypress in OnChar

10. Resizing a dialog based app based on its view's size

11. Control in dialog detecting moved dialog.

12. Adding Another MFC Dialog to the Dialog base application

 

 
Powered by phpBB® Forum Software