SetWindowsHookEx with WH_MOUSE not capturing mouse moves over HTCAPTION area

ε祈祈猫儿з 提交于 2020-01-03 05:09:29

问题


I try to use SetWindowsHookEx with WH_MOUSE to capture mouse move events. It work everywhere but over HTCAPTION areas (at least in my code sample ). I can't find any reference to this behavior and I tried to windbg into another application that do the same to monitor mouse moves. The method used is WH_MOUSE as well, and the events are generated even when the mouse is over caption areas. Hence, it should work except it doesn't.

Any ideas ?

Edit : I'm using this to hook in all processes. I built a separate dll that forward messages to some internal window in my application. I use dwThreadId = 0. I don't get mouse click in the caption area either.


回答1:


I figured it out :

MouseHookProc the mouseproc given to SetWindowsHookEx receive all the events of the mouse that mean I have to test that wParam is equal to WM_MOUSE or WM_NCMOUSEMOVE. When the cursor is over a client area WM_MOUSE is received and when it is over a nonclient area WM_NCMOUSEMOVE is fired (like in a normal message proc ).

LRESULT CALLBACK MouseHookProc(int nCode, WORD wParam, DWORD lParam)
{
    if(nCode>=0 && (wParam==WM_MOUSEMOVE || wParam==WM_NCMOUSEMOVE))
    {
        if(!hwnd)
            hwnd=FindWindow(0, "MyWindow");

        MSLLHOOKSTRUCT *mhs=(MSLLHOOKSTRUCT*)lParam;        
        PostMessage(hwnd, WM_MOUSEHOOK, wParam, 0);
    }
    return CallNextHookEx(hHook,nCode,wParam,lParam);
}

I thought that WM_MOUSE was some sort of corresponding value but not the real mouse message, but it is.



来源:https://stackoverflow.com/questions/940156/setwindowshookex-with-wh-mouse-not-capturing-mouse-moves-over-htcaption-area

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!