Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • 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
 
AndyAinscowFreelance programmer / ConsultantCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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