How would I go about using the GET_WHEEL_DELTA_WPARAM macro in C#?
GET_WHEEL_DELTA_WPARAM macro in C#
Asked Answered
A sanity check is required here. You cannot use C# to write code that's called by a global hook. That requires an injectable DLL. –
Sig
It seems to kind of work for me from C# with dllimport but sometimes hogs windows 'n stuff –
Hopi
High-order word, signed:
((short)(wParam>>16))
My method: public static short GetWheelDeltaWParam(int wparam) { return (short)(wparam >> 16); }, but it always return zero. I call it like this: GetWheelDeltaWParam((int)wParam); –
Hopi
If that doesn't work, try GetWDWP(unsigned int wparam) { return (short)((unsigned short)(wparam>>16)); } –
Tophole
unfortunately nope.. the first one should work, but it doesn't –
Hopi
Are you sure your wparam is correct? The problem may not be in this function. I don't see why it should be zero otherwise. –
Tophole
that may be the case, but I don't understand how I can move the mouse wheel and generate this event so that WHEEL_DELTA would be 0 –
Hopi
I guess you need to post more of your code. Perhaps in a new question since this one is strictly about the macro. –
Tophole
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))
My method: public static short GetWheelDeltaWParam(int wparam) { return (short)(wparam >> 16); }, but it always return zero. I call it like this: GetWheelDeltaWParam((int)wParam); –
Hopi
If that doesn't work, try GetWDWP(unsigned int wparam) { return (short)((unsigned short)(wparam>>16)); } –
Tophole
unfortunately nope.. the first one should work, but it doesn't –
Hopi
Are you sure your wparam is correct? The problem may not be in this function. I don't see why it should be zero otherwise. –
Tophole
that may be the case, but I don't understand how I can move the mouse wheel and generate this event so that WHEEL_DELTA would be 0 –
Hopi
I guess you need to post more of your code. Perhaps in a new question since this one is strictly about the macro. –
Tophole
There's the MouseWheelEventArgs.Delta Property:
Gets a value that indicates the amount that the mouse wheel has changed.
private void MouseWheelHandler(object sender, MouseWheelEventArgs e)
{
if (e.Delta > 0)
{
// Do one thing
}
else if (e.Delta < 0)
{
// Do the other thing
}
}
unfortunately I forgot to mention I am using global hooks from user32.dll with dllimport so I don't have access to such fancy objects.. –
Hopi
© 2022 - 2024 — McMap. All rights reserved.