0

我试图通过光标下的子窗口拦截鼠标滚轮。但有些不对劲。似乎消息发送了很多次。我做错了什么?

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;
}
4

0 回答 0