?
Solved

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

Posted on 2004-04-28
4
Medium Priority
?
192 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 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

800 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