开发者

How to get virtkey value for WM_KEYDOWN in WS_CHILD?

I want to know the value of virtual key pressed whe开发者_如何学Cn a child window(like 'edit' or 'button') has focus.

How to do that?


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.


You could catch them at the level of the message loop (before calling DispatchMessage). Nasty but will work.


You could use the GetKeyState Win32 API from within a WM_SETFOCUS handler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜