开发者

Touch API: disable legacy windows messages

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 s开发者_Python百科olution.


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());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜