C# 中的 GET_WHEEL_DELTA_WPARAM 宏

发布于 2025-01-06 04:56:26 字数 160 浏览 0 评论 0原文

我将如何使用 C# 中的 GET_WHEEL_DELTA_WPARAM 宏?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光沙漏 2025-01-13 04:56:27

MouseWheelEventArgs.Delta 属性

获取一个值,该值指示鼠标滚轮已更改的量。

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

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
    }
}
万劫不复 2025-01-13 04:56:26

为了最大程度地清晰起见,我将定义一组如下所示的函数:

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);
    }
}

然后使用如下所示的函数,其中 wParam 是从处理 Win32 中获得的 WPARAM 参数>WM_MOUSEWHEELWM_MOUSEHWHEEL 消息:

int zDelta = NativeMethods.GET_WHEEL_DELTA_WPARAM(wParam);

您可能需要抑制溢出检查才能使其正常工作。为此,请更改项目设置,或将相关转换函数包装在未选中块

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.

我喜欢麦丽素 2025-01-13 04:56:26

高位字,签名:

 ((short)(wParam>>16))

High-order word, signed:

 ((short)(wParam>>16))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文