Solved

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

Posted on 2004-04-28
4
189 Views
Last Modified: 2013-11-20
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
Comment
Question by:pimpernel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 125 total points
ID: 10946615
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
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 10946621
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
 

Author Comment

by:pimpernel
ID: 10946684
Thanks, AlexFM, it works !!
0
 
LVL 13

Expert Comment

by:SteH
ID: 10947711
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question