tags:

views:

521

answers:

2

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.

A: 

A few questions: Are you using this to hook the mouse in your own process or other processes? Are you using dwThreadId = 0? Are you getting mouse clicks over the caption area?

Mo Flanagan
A: 

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.

Emmanuel Caradec