4
votes

To see the right click event I am referring to, see this video.

I am working on an application that adds a zoom button in a Windows Forms application. When the user touches the button, the application should continuously zoom the window. This works by monitoring the mouse down event on the button. While the mouse is down, a timer continues to zoom the view in. This works fine so long as the users finger slides after the initial touch. However, if the user pushes on one spot the entire time, they will get a little wait circle then a right click event.

I've added the code from this link to the application:

public bool PreFilterMessage(ref Message m)
{
    // Filter out WM_NCRBUTTONDOWN/UP/DBLCLK
    if (m.Msg == 0xA4 || m.Msg == 0xA5 || m.Msg == 0xA6) return true;
    // Filter out WM_RBUTTONDOWN/UP/DBLCLK
    if (m.Msg == 0x204 || m.Msg == 0x205 || m.Msg == 0x206) return true;
    return false;
}

This code disables the resulting right-click event. However, the circle still happens and a mousedown event does not happen. Is there a way to make any physical touch count as a mouse down and not start the right click process?


Edit I tried going to Control Panel -> Pen and Touch and disabling the Press and Hold for right click feature. This disabled the spin icon, but the mouse down still doesn't occur unless the user moves their finger slightly. I don't see why a user has to scribble to hold down a button.

2

2 Answers

0
votes

The circle shown on touch is a gesture introduced in Windows 7 for right-click. It is called Press and Hold.

If you want to completely disable this gesture, you need to tell the operation system by calling SetGestureConfig function when initialize your form. This function allows you to explicitly specify which gestures are supported by your control.

0
votes

Please try this, it is working for me in Windows 10. This is not a global system change, press&hold will continue to work in OS and other programs. It disables press&hold only for your window.

. . .

[DllImport("kernel32.dll", EntryPoint = "GlobalAddAtomA", CharSet=CharSet.Ansi)]
static extern UInt16 GlobalAddAtom(string lpString);

[DllImport("user32.dll", EntryPoint = "SetPropA", CharSet = CharSet.Ansi)]
static extern UInt32 SetProp(IntPtr hWnd, UInt32 lpString, UInt32 hData);

. . .

UInt16 atom = GlobalAddAtom("MicrosoftTabletPenServiceProperty");
if (atom != 0)
    SetProp(this.Handle, (UInt32)atom, 1);

. . .