Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GET_WHEEL_DELTA_WPARAM macro in C#

How would I go about using the GET_WHEEL_DELTA_WPARAM macro in C#?

like image 308
user1151923 Avatar asked Feb 15 '12 23:02

user1151923


2 Answers

For maximum clarity, I would define a set of functions like this:

internal static class NativeMethods
{
    internal static ushort HIWORD(IntPtr dwValue)
    {
        return (ushort)((((long)dwValue) >> 0x10) & 0xffff);
    }

    internal static ushort HIWORD(uint dwValue)
    {
        return (ushort)(dwValue >> 0x10);
    }

    internal static int GET_WHEEL_DELTA_WPARAM(IntPtr wParam)
    {
        return (short)HIWORD(wParam);
    }

    internal static int GET_WHEEL_DELTA_WPARAM(uint wParam)
    {
        return (short)HIWORD(wParam);
    }
}

And then use the function like so, where wParam is the WPARAM parameter you get from handling the Win32 WM_MOUSEWHEEL or WM_MOUSEHWHEEL messages:

int zDelta = NativeMethods.GET_WHEEL_DELTA_WPARAM(wParam);

You might need to suppress overflow-checking in order for this to work properly. To do so, either change your project settings, or wrap the relevant conversion functions in an unchecked block.

like image 108
Cody Gray Avatar answered Sep 28 '22 15:09

Cody Gray


High-order word, signed:

 ((short)(wParam>>16))
like image 43
rasmus Avatar answered Sep 28 '22 13:09

rasmus