-
July 12th, 2014, 04:47 AM
#1
WM_KEYDOWN and focus
If I click on a button then it will keep the focus and I won't get any WM_KEYDOWN messages any more as long as I dont click outside and then back on the window.
What is the cause of this behaviour and how to avoid it?
The button:
Code:
switch (message)
{
case WM_CREATE:
CreateWindowExA(WS_EX_CLIENTEDGE,"BUTTON", "Play",
WS_CHILD|WS_VISIBLE,
20, 20, 80, 25, hWnd,
(HMENU)IDB_PLAY, 0, NULL);
Last edited by MasterDucky; July 12th, 2014 at 04:50 AM.
-
July 12th, 2014, 08:37 AM
#2
Re: WM_KEYDOWN and focus
Originally Posted by MasterDucky
If I click on a button then it will keep the focus and I won't get any WM_KEYDOWN messages any more as long as I dont click outside and then back on the window.
What is the cause of this behaviour?
It is "by design". Example: you "click" some button (press but release it yet!), but then you understand that this button-click would be wrong. So you move cursor from this button and after that release the button. In such a case no button-click event will be generated.
Originally Posted by MasterDucky
I... how to avoid it?
What for?
Victor Nijegorodov
-
July 12th, 2014, 12:34 PM
#3
Re: WM_KEYDOWN and focus
Yes but I need to push that button to start the application. After that on the other hand I want to handle WM_KEYDOWN messages.
But since the focus stays on the button I dont get the WM_KEYDOWN messages.
-
July 13th, 2014, 11:52 PM
#4
Re: WM_KEYDOWN and focus
Originally Posted by MasterDucky
Yes but I need to push that button to start the application. After that on the other hand I want to handle WM_KEYDOWN messages.
But since the focus stays on the button I dont get the WM_KEYDOWN messages.
Forcible focus displacing is a sort of inelegant solution as for me.
There are several standard mechanisms in Windows to process keyboard input transparently and independent of current focus location: 1) translating accelerators, 2) hooking message loop and 3) hooking keyboard input at low level. All those ones have their merits and demerits, depending on the ultimate goals to be achieved.
Best regards,
Igor
-
July 12th, 2014, 01:55 PM
#5
Re: WM_KEYDOWN and focus
In the code that handles the button click have you tried changing the focus?
See http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
July 12th, 2014, 03:15 PM
#6
Re: WM_KEYDOWN and focus
It worked. Thank you.
First I put it in the case that called the play() in the menu not on the button that's why it didn't work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|