触摸API:禁用旧版Windows消息

时间:2011-03-03 08:35:22

标签: c# winforms windows-7 touch

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

我知道有一个workaround,但我对其他解决方案感兴趣。

1 个答案:

答案 0 :(得分: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;
    }
}

在main中:

Application.AddMessageFilter(new MouseMessageFilter());