Solved

Button doesn't recieve WM_KEYDOWN for VK_RETURN

Posted on 2008-06-18
9
931 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ Language error 28 220
Delphi Mdi application Child forms get behind control 7 216
Best way to accomplish this task? 3 88
Need a complete list of ASP.NET page load events 3 47
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

832 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