Solved

Button doesn't recieve WM_KEYDOWN for VK_RETURN

Posted on 2008-06-18
9
940 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
[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
  • 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
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!

 

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

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

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