title: Disable touch visual feedback on windows 8.1 (programmatically) [Desktop App]
body: <p>I have a C# WPF application intended specifically for Win8.1 (a desktop app, NOT metro).</p>
  
  <p>I want users to be able to use touch injections but I'm trying to disable the visualization feedback that windows creates for a Tap gesture Press Hold and Drag (like selecting multiple files on desktop) and other gestures (zooming scrolling etc).</p>
  
  <p>After Searching the web for a long time I've found this post:
  <a href="http://blogs.msdn.com/b/oldnewthing/archive/2014/10/22/10566383.aspx" rel="nofollow noreferrer">How do I disable Windows 8 touch contact visualizations for my application?</a>
  So I tried to do the same...</p>
  
  <p>I tried this (Will put my Win32 class at the end)</p>
  
  <pre><code>public void DisableGestureVisualization()
  {
      const int SPI_SETCONTACTVISUALIZATION = 0x2019;
      const int SPI_SETGESTUREVISUALIZATION = 0x201B;
      ulong gv = 0;
      Logger.Debug(!Win32.SystemParametersInfo(SPI_SETGESTUREVISUALIZATION, 0, ref gv, 0)
          ? @"Failed SystemParametersInfo SPI_SETGESTUREVISUALIZATION"
          : @"Successfuly returned from SystemParametersInfo SPI_SETGESTUREVISUALIZATION");
  
      Logger.Debug(!Win32.SystemParametersInfo(SPI_SETCONTACTVISUALIZATION, 0, ref gv, 0)
          ? @"Failed SystemParametersInfo SPI_SETCONTACTVISUALIZATION"
          : @"Successfuly returned from SystemParametersInfo SPI_SETCONTACTVISUALIZATION");
  }
  </code></pre>
  
  <p>And also this:</p>
  
  <pre><code>public void TryDisableWindowsVisualFeedback(IntPtr hWnd)
  {
      bool enable = false;
      foreach (Win32.FEEDBACK_TYPE type in Enum.GetValues(typeof(Win32.FEEDBACK_TYPE)))
      {
          if (type == Win32.FEEDBACK_TYPE.FEEDBACK_MAX)
          {
              continue;
          }
  
          Logger.Debug(!Win32.SetWindowFeedbackSetting(hWnd, type, 0, 4, ref enable) 
                 ? @"Failed to SetWindowFeedbackSetting for " + type
                 : @"Successfuly returned from SetWindowFeedbackSetting for " + type);
      }
  }
  </code></pre>
  
  <p>And I call this from my WPF app like this:</p>
  
  <pre><code>private void MainWindow_Loaded(object sender, RoutedEventArgs e)
  {
      Window window = Window.GetWindow(this);
      var wih = new WindowInteropHelper(window);
      IntPtr hWnd = wih.Handle;
      TryDisableWindowsVisualFeedback(hWnd);
  }
  </code></pre>
  
  <p>This is my auxiliary Win32 class:</p>
  
  <pre><code>internal class Win32
  {
      [DllImport("user32.dll", SetLastError = true)]
      [return: MarshalAs(UnmanagedType.Bool)]
      public static extern bool SystemParametersInfo(
          uint uiAction,
          uint uiParam,
          ref ulong pvParam,
          uint fWinIni
          );
  
      public enum FEEDBACK_TYPE : uint
      {
          FEEDBACK_TOUCH_CONTACTVISUALIZATION = 1,
          FEEDBACK_PEN_BARRELVISUALIZATION = 2,
          FEEDBACK_PEN_TAP = 3,
          FEEDBACK_PEN_DOUBLETAP = 4,
          FEEDBACK_PEN_PRESSANDHOLD = 5,
          FEEDBACK_PEN_RIGHTTAP = 6,
          FEEDBACK_TOUCH_TAP = 7,
          FEEDBACK_TOUCH_DOUBLETAP = 8,
          FEEDBACK_TOUCH_PRESSANDHOLD = 9,
          FEEDBACK_TOUCH_RIGHTTAP = 10,
          FEEDBACK_GESTURE_PRESSANDTAP = 11,
          FEEDBACK_MAX = 0xFFFFFFFF
      }
  
      [DllImport("user32.dll")]
      public static extern bool SetWindowFeedbackSetting(
          IntPtr hwnd,
          FEEDBACK_TYPE feedback,
          uint dwFlags,
          uint size,
          [In] ref bool configuration
          );
  
  }
  </code></pre>
  
  <p>Non of the above disabled the round gray tap visual feedback nor did it disable the small white circle that appears when holding and dragging.</p>
  
  <p>I even tried using the C# example in the blog:</p>
  
  <pre><code>Windows.UI.Input.PointerVisualizationSettings.
  GetForCurrentView().
  IsContactFeedbackEnabled = false;
  </code></pre>
  
  <p>This code works for a metro app, so I tried <a href="https://stackoverflow.com/questions/12745703/how-can-i-use-the-windows-ui-namespace-from-a-regular-non-store-win32-net-app">This SO post</a> and got the Windows namespace but when running the code I get </p>
  
  <pre><code>"An unhandled exception of type 'System.Exception' occurred in MyProg.exe
  WinRT information: Element not found.
  Additional information: Element not found."
  </code></pre>
  
  <p>From what I could figure out, the <code>PointerVisualizationSettings</code> is not supported from a desktop application so this way is doomed... </p>
  
  <p>If anyone can help me with this issue, please do.</p>
  
  <p>Thanks</p>