开发者

Multiple WndProc functions in Win32

开发者 https://www.devze.com 2023-04-06 23:28 出处:网络
This might be a dumb question, but can you register multiple 开发者_JAVA技巧WndProc functions in Win32? e.g. a framework catches some messages and my app is interested in other ones - how do I catch t

This might be a dumb question, but can you register multiple 开发者_JAVA技巧WndProc functions in Win32? e.g. a framework catches some messages and my app is interested in other ones - how do I catch them without modifying the framework code?


If I understand your intention correctly, you can do that by setting a hook. Assuming you know the thread whose message loop you'd like to hook, you can do something along these lines (unchecked):

SetWindowsHookEx(WH_CALLWNDPROC, yourHOOKPROC, NULL, theThreadId);


You can chain multiple message handling functions by using the function CallWindowProc instead of DefWindowProc.

Here is an example:

pfOriginalProc = SetWindowLong( hwnd, GWL_WNDPROC, (long) wndproc1 );    // First WNDPROC

pfOriginalProc2 = SetWindowLong( hwnd, GWL_WNDPROC, (long) wndproc2);   // Second WNDPROC, WILL EXECUTE FIRST!!


LRESULT wndproc1( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
    switch ( uMsg )
    {
      ...
      default:
         return CallWindowProc( pfOriginalProc, hwnd, uMsg, wParam, lParam );
    }


}


LRESULT wndproc2( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{

    switch ( uMsg )
    {
        ...
        default:
            return CallWindowProc( pfOriginalProc2, hwnd, uMsg, wParam, lParam );
    }
}
0

精彩评论

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