【问题标题】:Touch API: disable legacy windows messagesTouch API:禁用旧版 Windows 消息
【发布时间】:2011-03-03 08:35:22
【问题描述】:

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

我知道有一个 workaround 可以解决这个问题,但如果有其他解决方案我很感兴趣。

【问题讨论】:

    标签: c# winforms windows-7 touch


    【解决方案1】:

    您的控件可以像这样覆盖 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);
        }
    

    如果您的应用完全想忽略这些消息,请执行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;
        }
    }
    

    主要:

    Application.AddMessageFilter(new MouseMessageFilter());
    

    【讨论】:

    • 是的,我知道这个解决方案。您还可以检查鼠标消息是否由触摸生成并丢弃,因此您通常不会禁用它们。它适用于几乎所有鼠标消息,但不适用于 WM_MOUSELEAVE,I posted this in the MSDN forums. 我感谢您的 IMessageFilter 建议 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-20
    • 1970-01-01
    • 1970-01-01
    • 2015-11-23
    • 1970-01-01
    • 2012-01-02
    相关资源
    最近更新 更多