禁用用于 WPF 应用程序的 RealTimeStylus

Windows Presentation Foundation (WPF) 内置了对处理 Windows 7 触摸输入的支持。 该支持通过平板电脑平台的实时触控输入(以 OnStylusDownOnStylusUpOnStylusMove 事件的形式)实现。 Windows 7 还通过 Win32 WM_TOUCH 窗口消息提供多点触控输入。 这两个 API 在同一 HWND 上相互排斥。 通过平板电脑平台(WPF 应用程序的默认值)启用触摸输入会禁用 WM_TOUCH 消息。 因此,若要使用WM_TOUCH从 WPF 窗口接收触摸消息,必须禁用 WPF 中的内置触笔支持。 这适用于托管使用WM_TOUCH组件的 WPF 窗口等方案。

若要禁用 WPF 侦听触笔输入,请删除 WPF 窗口添加的任何平板电脑支持。

示例:

以下示例代码演示如何使用反射删除默认平板电脑平台支持。

public static void DisableWPFTabletSupport()
{
    // Get a collection of the tablet devices for this window.
    TabletDeviceCollection devices = System.Windows.Input.Tablet.TabletDevices;

    if (devices.Count > 0)
    {
        // Get the Type of InputManager.
        Type inputManagerType = typeof(System.Windows.Input.InputManager);

        // Call the StylusLogic method on the InputManager.Current instance.
        object stylusLogic = inputManagerType.InvokeMember("StylusLogic",
                    BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                    null, InputManager.Current, null);

        if (stylusLogic != null)
        {
            //  Get the type of the stylusLogic returned from the call to StylusLogic.
            Type stylusLogicType = stylusLogic.GetType();

            // Loop until there are no more devices to remove.
            while (devices.Count > 0)
            {
                // Remove the first tablet device in the devices collection.
                stylusLogicType.InvokeMember("OnTabletRemoved",
                        BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic,
                        null, stylusLogic, new object[] { (uint)0 });
            }
        }

    }
}

另请参阅