次の方法で共有


WPF アプリケーションの RealTimeStylus を無効にする

Windows Presentation Foundation (WPF) には、Windows 7 タッチ入力の処理のサポートが組み込まれています。 サポートは、タブレット プラットフォームのリアルタイム スタイラス入力を通じて、 OnStylusDownOnStylusUp、および OnStylusMove イベントとして提供されます。 Windows 7 では、Win32 WM_TOUCH ウィンドウ メッセージとしてマルチタッチ入力も提供されます。 これら 2 つの 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 });
            }
        }

    }
}

こちらも参照ください