我有一个专门用于Win8.1的C#WPF应用程序(桌面应用程序,不是Metro)。

我希望用户能够使用触摸注入,但是我试图禁用Windows为Tap手势创建的可视化反馈。按住Hold和Drag(例如在桌面上选择多个文件)以及其他手势(缩放滚动等)。

在网上搜索了很长时间后,我发现了这篇文章:
How do I disable Windows 8 touch contact visualizations for my application?
所以我尝试做同样的事情...

我试过了(将Win32类放在最后)

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");
}


还有这个:

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


我从WPF应用程序中这样调用它:

private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
    Window window = Window.GetWindow(this);
    var wih = new WindowInteropHelper(window);
    IntPtr hWnd = wih.Handle;
    TryDisableWindowsVisualFeedback(hWnd);
}


这是我的辅助Win32类:

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

}


上面的方法都不能禁用灰色的点击视觉反馈,也不能禁用按住并拖动时出现的白色小圆圈。

我什至尝试在博客中使用C#示例:

Windows.UI.Input.PointerVisualizationSettings.
GetForCurrentView().
IsContactFeedbackEnabled = false;


该代码适用于Metro应用程序,因此我尝试This SO post并获得了Windows名称空间,但是在运行代码时却得到了

"An unhandled exception of type 'System.Exception' occurred in MyProg.exe
WinRT information: Element not found.
Additional information: Element not found."


据我所知,桌面应用程序不支持PointerVisualizationSettings,所以这种方式注定了...

如果有人可以帮助我解决此问题,请这样做。

谢谢

最佳答案

我遇到了类似的问题,可以通过添加以下内容来消除点击手势反馈

Stylus.IsTapFeedbackEnabled = "False" to my root window.

关于c# - 在Windows 8.1上(以编程方式)禁用触摸式视觉反馈[Desktop App],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27550373/

10-12 00:40