Hello All

I’m trying to hook the mouse scroll wheel using SetWindowsHookEx with WH_MOUSE_LL. The callback function I am using operates correctly, and identifies when the mouse wheel is scrolled. However I am unsure of how to identify which direction the mouse has been scrolled. My code so far:

LRESULT CALLBACK mouseProcedure(int nCode, WPARAM wParam, LPARAM lParam)
{
    if (nCode == HC_ACTION)
    {
        switch (wParam)
        {
            case WM_MOUSEWHEEL:
                // Identify mouse wheel direction here..

                break;
            default:
                break;
        }
    }

    return false;
}

Any thoughts, tips or recommendations would be greatly appreciated.

Cheers

Cam

Refence taken from MSDN
wParam
The high-order word indicates the distance the wheel is rotated, expressed in multiples or divisions of WHEEL_DELTA, which is 120. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user.

hi,
I misunderstood your problem.

Here you will not receive wParam for WM_MOUSEWHEEL notification.

lparam->MOUSEHOOKSTRUCT will contain the handle to window which will receive the mouse message corresponding to the mouse event.

Here you will not receive wParam for WM_MOUSEWHEEL notification.
lparam->MOUSEHOOKSTRUCT will contain the handle to window which will receive the mouse message corresponding to the mouse event.

Wrong,
1) wParam will receive WM_MOUSEWHEEL notification
2) lparam->MOUSEHOOKSTRUCT is not a valid identity
3) MOUSEHOOKSTRUCT does not contain any handle to any window.

lParam does not contain any object named MOUSEHOOKSTRUCT but is a Pointer to a MOUSEHOOKSTRUCT. & the latter does not contain any handle but info to the Mouse Event. Just use the lParam as:

MSLLHOOKSTRUCT *mouseInfo = (MSLLHOOKSTRUCT*)lParam;
if(HIWORD(mouseInfo->mouseData)>0)
  WheelRotatedForward();
else
  WheelRotatedBackward();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.