How would I go about using the GET_WHEEL_DELTA_WPARAM macro in C#?
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.
High-order word, signed:
((short)(wParam>>16))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With