Solved

Button doesn't recieve WM_KEYDOWN for VK_RETURN

Posted on 2008-06-18
9
938 Views
Last Modified: 2013-12-03
I have a window (non-dialog) and some buttons.

When I start the application, the focus is on one of the buttons, however enter doesn't click the button, unless I first move around for example tab to another button then press enter to click that one, or even tab back to the original and it will work this time.

I've investigated what happens. The button does in fact recieve the WM_KEYDOWN for VK_RETURN, I've looked for it in Spy++, but the button's wndproc does not.

Even after I tab around, the button's wndproc still doesn't recieve it, but this time the parent gets the BN_CLICKED notification.

I'm looking for a way to get the WM_KEYDOWN for VK_RETURN, or at least a way to have the parent get the BN_CLICKED initially.
0
Comment
Question by:imw225
  • 5
  • 4
9 Comments
 
LVL 40

Expert Comment

by:evilrix
ID: 21812017
I take it this button as set as the default button for the dialog?
0
 

Author Comment

by:imw225
ID: 21812128
No, it\s just the first tabstop, in some situations some buttons are visible, and sometimes others, so I need the first tabstop to get the focus.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 21812184
Ah, I've just noticed this isn't a dialog (sorry I missed that before). So you don't want Enter to always press this button, only when it has focus but initially, although it seems to have focus, it doesn't get clicked? Is that right? Sorry if I am repeating you but I just want to be sure I fully understand the problem.

How are you setting focus on this button? Are you doing this programatically,, (for example during the OnShow() event) or are you relying on some default z-order?
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:imw225
ID: 21812215
Yes, it's correct.

At first I was relying on it being the first tabstop, but I've also tried ::SetFocus button's hWnd and I get the same result.

I've read about other people having this problem on some forums, however no solution was found.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 21812239
Long shot but have you also tried calling SetActiveWindow() for the buttons handle?
0
 

Author Comment

by:imw225
ID: 21812307
Yep, tried SetActiveWindow, SetForegroundWindow, no change.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 21812314
Sorry, I'm all out then :(
0
 

Author Comment

by:imw225
ID: 21822153
Solved by setting the BS_DEFPUSHBUTTON style along with giving focus.
0
 

Accepted Solution

by:
imw225 earned 0 total points
ID: 21822177
By the way if anyone else has this problem, my window is not a dialog yet the BS_DEFPUSHBUTTON style works.
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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

831 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