Поделиться через


Отключение RealTimeStylus для приложений WPF

Windows Presentation Foundation (WPF) поддерживает обработку сенсорных входных данных Windows 7. Поддержка осуществляется через ввод с помощью стилуса на планшетной платформе в режиме реального времени в виде событий OnStylusDown, OnStylusUpи OnStylusMove. Windows 7 также предоставляет мультитач-ввод в виде оконных сообщений Win32 WM_TOUCH. Эти два API являются взаимоисключающими для одного И ТОГО же HWND. Включение сенсорного ввода через планшетную платформу (по умолчанию для приложений WPF) отключает WM_TOUCH сообщения. В результате, чтобы использовать WM_TOUCH для получения сенсорных сообщений из окна WPF, необходимо отключить встроенную поддержку пера в WPF. Это применимо в сценарии, например в окне WPF, где размещен компонент, использующий WM_TOUCH.

Чтобы отключить прослушивание 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 });
            }
        }

    }
}

См. также