Win32的。钩。通过子窗口拦截WM_MOUSEWHEEL

时间:2013-08-28 18:53:29

标签: c++ winapi hook

我试图通过光标下的子窗口拦截鼠标滚轮。但有些事情是错的。好像消息多次发送。我做错了什么?

LRESULT CALLBACK MouseProc(__in  int     nCode,
                           __in  WPARAM  wParam,
                           __in  LPARAM  lParam)
{
    LRESULT      ret = 0;
    static  BOOL b   = TRUE;

    if (wParam == WM_MOUSEWHEEL)
    {
        if (b)
        {
            MOUSEHOOKSTRUCTEX *pMhs = (MOUSEHOOKSTRUCTEX *)lParam;
            short zDelta            = HIWORD(pMhs->mouseData);
            POINT pt;
            GetCursorPos(&pt);
            LPARAM lParam = MAKELPARAM(pt.x, pt.y);

            HWND hWnd = WindowFromPoint(pt);

            b = FALSE;
            SendMessage(hWnd, WM_MOUSEWHEEL, zDelta, lParam);
        }
        else
        {
            b = TRUE;
        }

        ret = 1;
    }
    else
    {
        CallNextHookEx(0, nCode, wParam, lParam);
    }

    return ret;
}

0 个答案:

没有答案