WinApi equivalent .NET KeyPreview

.Net has a KeyPreview function. How to do it in WinApi. Maybe I don't necessarily need this, but my hWnd has WM_KEYDOWN, but it doesn't get it when my textbox has focus. How can I achieve this? Thanks to

* Using pure Win32API ...

Is there an alternative how I can handle the WM_KEYDOWN text field?

+2


a source to share


3 answers


You can try subclassing the edit control. Either "instance subclassing" to catch messages for only one window, or "global subclassing" to catch messages for all windows of that class (in your application, not system-wide).

The example here ( http://msdn.microsoft.com/en-us/library/ms997565.aspx ) shows how to subclass an edit control and catch the WM_GETDLGCODE message - it won't be difficult to change it to WM_KEYDOWN.



You may have problems viewing the keys used for dialog commands, for example. TAB or RETURN, as they can be trapped up the food chain. You may have to look at changing WM_GETDLGCODE as well.

0


a source


  • If you are using MFC you can look at PreTranslateMessage (I'm not sure about PreTranslateMessage, but you can easily check if there is enough to override the function).
  • You can install a keyboard hook.


0


a source


WinAPI has no such ability to catch messages belonging to controls in the parent window's window procedure (although there are some exceptions). What .NET basically does is that it routes all messages from all controls, including the parent window, to a single window procedure. Then it's easy to catch all messages in one place. This is your way to set the window procedures of all controls into one procedure and there to catch all the messages. Since the window procedure also takes an hwnd parameter, it is also easy to define the control to which the message belongs.

0


a source







All Articles