Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi there, just been learning the simple stuff in winapi for gui creation, and i've got a bit of a problem. When i open an instance of the application, and press a button, the WM_KEYDOWN catches it, but when i have any sort of control selected, like an edit control, keystrokes are just lost or something. Is there some sort of roundabout way that each child window recieves keystrokes or something? and if there is, how can i determine if a key is pressed from the parent window?
Posted

The WM_KEYDOWN message is posted to the window with input focus. You can set a message hook by SetWindowsHookEx to catch the keystrokes. Or you can examine the message in your message loop. But these methods arnt really good because handling a message twice will cause unexpected results. Better you create a accelerator table by CreateAcceleratorTable or LoadAccelerators for special key strokes. They must be translated by TranslateAccelerator.
Regards.
 
Share this answer
 
Comments
FatalCatharsis 26-Aug-11 9:27am    
umm, that's a little beyond my winapi knowledge or ability. what is a message hook, and why would i need one? and what is an accelerator table?
mbue 26-Aug-11 10:15am    
An accelerator table translates special key strokes into command messages. You can define ie. F2 to a command (WM_COMMAND) to do anything special.
Use the function names above for a further internet or msdn search.
Regards.
They are not lost. They go to the edit control class procedure. You don't see them since they don't come to your procedure anymore.
But the control itself send notification to its parent (your window) in form of EN_XXX commands in a WM_COMMAND message.
See http://msdn.microsoft.com/en-us/library/ff485924%28v=VS.85%29.aspx[^]
 
Share this answer
 
Comments
FatalCatharsis 26-Aug-11 9:33am    
yes, i understand notifications, but is there any specific notification that will give keypress data within that window? and if not, is sublcassing a possibility, if i were to create a custom message that sends a custom notification with the keypress data, or something similar, or am i way off?
FatalCatharsis 26-Aug-11 11:04am    
i accepted solution 2, but let it be known, that this solution also put me on the right track, so thanks Emilio.
Emilio Garavaglia 26-Aug-11 11:39am    
Thanks to let me know.
Consider also as an alternative to hooks, subclassing
http://msdn.microsoft.com/en-us/library/ms633570%28v=vs.85%29.aspx#subclassing_window
Does this[^] help? I got it via a google search for "winapi control keystroke".
 
Share this answer
 
Comments
FatalCatharsis 26-Aug-11 9:25am    
nah, sorry, that doesn't help much cause i'm not using mfc.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900