0

I use SetWindowsHookEx() to capture WM_MOUSEMOVE and than use TrackMouseEvent to capture the WM_MOUSELEAVE, but the WM_MOUSELEAVE is not captured by my MouseHook.

Using Spy++ I can se that WM_MOUSELEAVE is fired, but my MouseHook not capture the message. Why?

LRESULT CALLBACK MouseHook(int nCode, WPARAM wp, LPARAM lp)
{
    MOUSEHOOKSTRUCT   *pmh = (MOUSEHOOKSTRUCT   *) lp;

    if (nCode >= 0) {
        if( wp == WM_MOUSEMOVE) {
            if(!tracking){
                TRACKMOUSEEVENT tme;
                tme.cbSize = sizeof(TRACKMOUSEEVENT);
                tme.dwFlags = TME_LEAVE;
                tme.hwndTrack = pmh->hwnd;
                TrackMouseEvent(&tme);
                tracking = true;
            }
        }
    }

    if( wp == WM_MOUSELEAVE){
        if(tracking){
            TRACKMOUSEEVENT tme;
            tme.cbSize = sizeof(TRACKMOUSEEVENT);
            tme.dwFlags = TME_LEAVE & TME_CANCEL;
            tme.hwndTrack = pmh->hwnd;
            TrackMouseEvent(&tme);
            tracking = false;
        }
    }
    return CallNextHookEx(NULL, nCode, wp, lp);   
}
4

1 回答 1

2

WM_MOUSELEAVE isn't a true mouse message, it's generated by an internal timer proc that's established when you call TrackMouseEvent (that repeatedly checks if the mouse has left the window and sends a message to it when it does).

You could probably catch it with a WH_CALLWNDPROC hook.

于 2013-06-07T21:21:56.983 回答