GET_WHEEL_DELTA_WPARAM macro in C #

How can I use the GET_WHEEL_DELTA_WPARAM macro in C #?

+4
source share
3 answers

High order word signed:

((short)(wParam>>16)) 
+1
source

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

 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 a function where wParam is the wParam parameter that you get from Win32 message processing WM_MOUSEWHEEL or WM_MOUSEHWHEEL :

 int zDelta = NativeMethods.GET_WHEEL_DELTA_WPARAM(wParam); 

You may need to suppress the overflow check for this to work correctly. To do this, change the project settings or wrap the appropriate conversion functions in an unchecked block.

+6
source

Here's the MouseWheelEventArgs.Delta Property :

Gets a value indicating the amount that the mouse wheel changed.

 private void MouseWheelHandler(object sender, MouseWheelEventArgs e) { if (e.Delta > 0) { // Do one thing } else if (e.Delta < 0) { // Do the other thing } } 
0
source

Source: https://habr.com/ru/post/1396737/


All Articles