• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

do sth when "space" is pressed in dialog based vc++ app

Hello,
is there a way to "bind" the space-key to a button (without SetWindowsHookEx) so that I can toggle the button with the space key ??
thanks...
0
pimpernel
Asked:
pimpernel
1 Solution
 
AlexFMCommented:
BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
    if( pMsg->message == WM_KEYDOWN )
    {
        if( pMsg->wParam == VK_SPACE )
        {
            // do here what you need

            ::TranslateMessage(pMsg);
            ::DispatchMessage(pMsg);
            return TRUE;
        }
    }
      
    return CDialog::PreTranslateMessage(pMsg);
}
0
 
AndyAinscowCommented:
You can override PreTranslateMessage and handle the space key there.
You could create an accelerator and use it to generate the same command as the button.
0
 
pimpernelAuthor Commented:
Thanks, AlexFM, it works !!
0
 
SteHCommented:
It can be done by creating a push button. Choose check box from the palette and set its style to push button. This will change its state when space is pressed without doing any coding!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now