Touch API:禁用旧版 Windows 消息

发布于 2024-10-20 02:35:46 字数 270 浏览 0 评论 0原文

我为我的表单调用了 RegisterTouchWindow,现在我收到了原始的 WM_TOUCH 消息,但这些消息还会生成 WM_MOUSEDOWN、WM_MOUSEMOVE 和 WM_MOUSEUP。有没有办法禁用这种行为?我只想获取 WM_TOUCH 消息。

我知道有一个解决方法但我很感兴趣是否还有其他解决方案。

I called RegisterTouchWindow for my form, now I'm getting the raw WM_TOUCH messages, but these messages also generate WM_MOUSEDOWN, WM_MOUSEMOVE and WM_MOUSEUP. Is there a way to disable this behavior? I only want to get the WM_TOUCH messages.

I know there is a workaround for this but I'm interested if there are any other solution.

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

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

发布评论

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

评论(1

水染的天色ゝ 2024-10-27 02:35:46

您的控件可以像这样覆盖 WndProc:

    const int WM_LBUTTONDOWN = 0x201;
    const int WM_LBUTTONUP = 0x202;
    const int WM_MOUSEMOVE = 0x200;

    protected override void WndProc(ref Message m)
    {
        if (m.Msg == WM_LBUTTONDOWN 
           || m.Msg == WM_LBUTTONUP 
           || m.Msg == WM_MOUSEMOVE) 
            return;
        base.WndProc(ref m);
    }

如果您的应用程序完全想要忽略这些消息,请执行类似 显示在 main 中

public class MouseMessageFilter : IMessageFilter
{
    const int WM_LBUTTONDOWN = 0x201;
    const int WM_LBUTTONUP = 0x202;
    const int WM_MOUSEMOVE = 0x200;

    public bool PreFilterMessage(ref Message m)
    {
        if (m.Msg == WM_LBUTTONDOWN)  return true;
        if (m.Msg == WM_LBUTTONUP)    return true;
        if (m.Msg == WM_MOUSEMOVE)    return true;
        return false;
    }
}

Application.AddMessageFilter(new MouseMessageFilter());

Your control could override WndProc like this:

    const int WM_LBUTTONDOWN = 0x201;
    const int WM_LBUTTONUP = 0x202;
    const int WM_MOUSEMOVE = 0x200;

    protected override void WndProc(ref Message m)
    {
        if (m.Msg == WM_LBUTTONDOWN 
           || m.Msg == WM_LBUTTONUP 
           || m.Msg == WM_MOUSEMOVE) 
            return;
        base.WndProc(ref m);
    }

If your app completely want's to ignore those messages do something like shown here

public class MouseMessageFilter : IMessageFilter
{
    const int WM_LBUTTONDOWN = 0x201;
    const int WM_LBUTTONUP = 0x202;
    const int WM_MOUSEMOVE = 0x200;

    public bool PreFilterMessage(ref Message m)
    {
        if (m.Msg == WM_LBUTTONDOWN)  return true;
        if (m.Msg == WM_LBUTTONUP)    return true;
        if (m.Msg == WM_MOUSEMOVE)    return true;
        return false;
    }
}

in main :

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