Solved

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

Posted on 2004-04-28
4
190 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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