Using Win32 API, when a child window has the keyboard focus, how can you tell whether a key is pressed (preferably without using functions like GetKeyState())? Is there a WM message that child windows send to the parent window when a key is pressed?
Win32 How To Tell If Key Pressed When A Child Window Has Focus?
Started by RhetoricalRuvim, Feb 13 2011 06:10 PM
3 replies to this topic
#1
Posted 13 February 2011 - 06:10 PM
|
|
|
#2
Posted 14 February 2011 - 12:25 AM
RhetoricalRuvim said:
Is there a WM message that child windows send to the parent window when a key is pressed?
Not that I am aware of. The focused window must relay the messages to its parent if you want this behavior.
#3
Posted 14 February 2011 - 07:36 AM
So does it relay the messages by default or is there some setting that I need to set in order for it to do that? And would the child window relay the messages to the parent window by sending some WM message? If so then what is the WM message uMsg value?
#4
Posted 14 February 2011 - 08:24 AM
If a message was not dropped (i.e. by setting it's result into something other than zero - indicating that it's been handled) usually the message will be sent to the target parent and continue that way until it hit the top most window. So if the focused window does not handle keyboard messages, then its parent will get the messages. However I don't believe that is your case. In your case I believe the focused window is capable to handle the messages, therefore it will automatically drop the messages.
You can subclass the window procedure of the child window so it will propagate the keyboard messages. Use Window api SetWindowLong if you want to subclass your child window procedure. With it you can change the window procedure address of the child window. Or you can use windows hook method. I have written a short tutorial on windows hook, if you want to choose this path. The tutorial does not directly address this issue, though. But I believe from there you can get some idea for a start.
You can subclass the window procedure of the child window so it will propagate the keyboard messages. Use Window api SetWindowLong if you want to subclass your child window procedure. With it you can change the window procedure address of the child window. Or you can use windows hook method. I have written a short tutorial on windows hook, if you want to choose this path. The tutorial does not directly address this issue, though. But I believe from there you can get some idea for a start.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









