I want to know the value of virtual key pressed when a child window(like 'edit' or 'button') has focus.
How to do that?
views:
201answers:
3
+1
A:
Well one way is to use
WNDPROC g_OldProc;
LRESULT CALLBACK MyEditWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
if ( uMsg == WM_KEYDOWN )
{
// Handle key down.
}
return g_OldProc( hwnd, uMsg, wParam, lParam );
}
then at some opportune moment
g_OldProc = (WNDPROC)GetWindowLongPtr( hEdit, GWLP_WNDPROC );
SetWindowLongPtr( hEdit, GWLP_WNDPROC, (LONG_PTR)MyEditWindowProc );
This will replace the window procedure of the hEdit control with your own window procedure that, in turn, calls the original window procedure.
Goz
2009-12-03 19:24:58
I'm assuming that SetClassLongPtr does not work because I use it on 'base' classes like 'button'.
hash
2009-12-03 20:12:24
I would assume SetClassLongPtr only affects windows created after the call. I don't KNOW on that one though. I've never had call to use it.
Goz
2009-12-03 20:44:07
You are right again, thank you much.
hash
2009-12-03 21:29:16
you're welcome :)
Goz
2009-12-03 22:03:38
A:
You could catch them at the level of the message loop (before calling DispatchMessage). Nasty but will work.
tyranid
2009-12-03 19:26:23
A:
You could use the GetKeyState Win32 API from within a WM_SETFOCUS handler.
Brian R. Bondy
2009-12-03 19:34:17