Ian Oakes
Ian Oakes

Reputation: 10253

Disable Windows 7 touch animation in WPF

In Windows 7 when you touch the screen there is a short animation that occurs at the touch point.

In my WPF app I want to display my own touch points, without showing the one supplied by Windows.

Any ideas on how to disable them in an app?

Upvotes: 1

Views: 1848

Answers (2)

Hugo
Hugo

Reputation: 1822

You can disable them on a per-control basis, though the best bet, specially for your particular case, if to do this on the root application's window, and any spawned windows (including popups). Add the following attached properties to the "" element in your XAML file, so you end up with something like this:

<Window x:Class="MyWPFTouchFreeApp"
... [<omitted elements>]
Stylus.IsTapFeedbackEnabled="False" Stylus.IsTouchFeedbackEnabled="False"
Stylus.IsPressAndHoldEnabled="False" Stylus.IsFlicksEnabled="False"
... [<any other omitted attributes>]
>
  <Grid ...

  </Grid>
</Window>

Also, if you use the Microsoft Surface Toolkit for Windows Touch (presently in beta), using a SurfaceWindow will automatically disable these for you (Popups must still be handled manually).

Upvotes: 4

Ian Oakes
Ian Oakes

Reputation: 10253

Found this today whilst taking a look at the Surface Toolkit for Windows Touch, seems to do the job quite nicely.

// override on the Window class
protected override void OnSourceInitialized(EventArgs e)
{
    EnableTabletGestures(this, false);
}

[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
public static extern short GlobalAddAtom(string atom);

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr RemoveProp(IntPtr hWnd, string atom);

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int SetProp(IntPtr hWnd, string atom, IntPtr handle);

public bool EnableTabletGestures(Window window, bool enable)
{
    var hWnd = ((HwndSource)PresentationSource.FromVisual(window)).Handle;

    long num = 0L;
    string atom = "MicrosoftTabletPenServiceProperty";
    num = GlobalAddAtom(atom);
    if (num == 0L)
    {
        return false;
    }
    if (enable)
    {
        return (RemoveProp(hWnd, atom).ToInt64() == 1L);
    }
    int num2 = 0x1010019;
    return (SetProp(hWnd, atom, new IntPtr(num2)) == 1);
}

Upvotes: 1

Related Questions