MBulli
MBulli

Reputation: 1709

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 solution.

Upvotes: 2

Views: 2246

Answers (1)

ralf.w.
ralf.w.

Reputation: 1696

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

Upvotes: 2

Related Questions