October 22nd, 2014

How do I disable Windows 8 touch contact visualizations for my application?

You might have an application (like a game) where the default touch contact visualizations are a distraction. In WinRT, you can disable the contact visualizations by simply saying

// JavaScript
Windows.UI.Input.PointerVisualizationSettings.
    getForCurrentView().
    isContactFeedbackEnabled = false;
// C#
Windows.UI.Input.PointerVisualizationSettings.
    GetForCurrentView().
    IsContactFeedbackEnabled = false;
// C++
Windows::UI::Input::PointerVisualizationSettings::
    GetForCurrentView()->
    IsContactFeedbackEnabled = false;

In Win32, you use the Set­Window­Feedback­Setting function. To demonstrate that, let’s take our scratch program and make this simple change:

BOOL
OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
{
 BOOL fEnabled = FALSE;
 SetWindowFeedbackSetting(hwnd,
    FEEDBACK_TOUCH_CONTACTVISUALIZATION,
    0, sizeof(fEnabled), &fEnabled);
 return TRUE;
}

The touch visualizations are white and the default window color is white, so the visualizations are hard to see in the scratch program. Let’s change the color to something that the visualizations will be more visible against.

    wc.hbrBackground = (HBRUSH)(COLOR_WINDOWTEXT + 1);

Run the program, and you’ll see that if you touch the window and drag your finger around, there is no little white circle and no white streak that follows your finger. (Note, however, that the Optimize visual feedback for projection to an external monitor, setting overrides the FEEDBACK_TOUCH_CONTACT­VISUALIZATION setting, so if you have projection contacts enabled, then you still get the dark circles. Another way to get dark circles is to stay up late and not get enough sleep.)

Although we disabled contact visualizations, we still get visualizations for gestures like tap or tap-and-hold. We can turn those off, too:

BOOL
OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
{
 BOOL fEnabled = FALSE;
 SetWindowFeedbackSetting(hwnd,
    FEEDBACK_TOUCH_CONTACTVISUALIZATION,
    0, sizeof(fEnabled), &fEnabled);
 SetWindowFeedbackSetting(hwnd,
    FEEDBACK_TOUCH_TAP,
    0, sizeof(fEnabled), &fEnabled);
 SetWindowFeedbackSetting(hwnd,
    FEEDBACK_TOUCH_DOUBLETAP,
    0, sizeof(fEnabled), &fEnabled);
 SetWindowFeedbackSetting(hwnd,
    FEEDBACK_TOUCH_PRESSANDHOLD,
    0, sizeof(fEnabled), &fEnabled);
 SetWindowFeedbackSetting(hwnd,
    FEEDBACK_TOUCH_RIGHTTAP,
    0, sizeof(fEnabled), &fEnabled);
 return TRUE;
}

The complete list of things you can disable is given by the FEEDBACK_TYPE enumeration.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.