[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1003
  • Last Modified:

Button doesn't recieve WM_KEYDOWN for VK_RETURN

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
imw225
Asked:
imw225
  • 5
  • 4
1 Solution
 
evilrixSenior Software Engineer (Avast)Commented:
I take it this button as set as the default button for the dialog?
0
 
imw225Author Commented:
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
 
evilrixSenior Software Engineer (Avast)Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
imw225Author Commented:
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
 
evilrixSenior Software Engineer (Avast)Commented:
Long shot but have you also tried calling SetActiveWindow() for the buttons handle?
0
 
imw225Author Commented:
Yep, tried SetActiveWindow, SetForegroundWindow, no change.
0
 
evilrixSenior Software Engineer (Avast)Commented:
Sorry, I'm all out then :(
0
 
imw225Author Commented:
Solved by setting the BS_DEFPUSHBUTTON style along with giving focus.
0
 
imw225Author Commented:
By the way if anyone else has this problem, my window is not a dialog yet the BS_DEFPUSHBUTTON style works.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now