Solved

Button doesn't recieve WM_KEYDOWN for VK_RETURN

Posted on 2008-06-18
9
920 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
Comment Utility
I take it this button as set as the default button for the dialog?
0
 

Author Comment

by:imw225
Comment Utility
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
Comment Utility
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
 

Author Comment

by:imw225
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 40

Expert Comment

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

Author Comment

by:imw225
Comment Utility
Yep, tried SetActiveWindow, SetForegroundWindow, no change.
0
 
LVL 40

Expert Comment

by:evilrix
Comment Utility
Sorry, I'm all out then :(
0
 

Author Comment

by:imw225
Comment Utility
Solved by setting the BS_DEFPUSHBUTTON style along with giving focus.
0
 

Accepted Solution

by:
imw225 earned 0 total points
Comment Utility
By the way if anyone else has this problem, my window is not a dialog yet the BS_DEFPUSHBUTTON style works.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now