zoukankan      html  css  js  c++  java
  • 2018-11-13-WPF-禁用实时触摸

    title author date CreateTime categories
    WPF 禁用实时触摸
    lindexi
    2018-11-13 10:45:37 +0800
    2018-5-4 21:0:38 +0800
    WPF 触摸

    微软想把 WPF 作为 win7 的触摸好用的框架,所以微软做了很多特殊的兼容。为了获得真实的触摸消息,微软提供了 OnStylusDown, OnStylusUp, 和 OnStylusMove 事件。 本文告诉大家如何使用代码禁用 WPF 的触摸消息,解决一些问题。

    在 win7 还提供了多点触摸 windows 消息 WM_TOUCH ,通过这两个 API 一个是 OnStylusDown 这些事件,另一个就是 WM_TOUCH ,用户可以拿到触摸消息。

    这两个 API 是相互独立,依靠相同的 HWND 。

    那么为什么需要禁用 WPF 的 RealTimeStylus ,因为在 WPF 触摸平台会禁用 WM_TOUCH 消息。如果想要使用 WM_TOUCH ,在 WPF 需要禁用 WPF 的触摸事件。

    如果没有禁用,就无法拿到 WM_TOUCH 消息,这个方法可以让自己定义自己的触摸。

    禁用的方法使用下面代码

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

    代码直接可以直接放在项目,代码是在微软文档复制。

    虽然禁用微软提供的触摸事件,可以修复很多坑,但是禁用了也是有很多新的坑,不过我就不在这里告诉大家。自己尝试运行下面代码,然后试试程序。

    为什么这样就可以禁用触摸,请看WPF 触摸到事件

    Disable the RealTimeStylus for WPF Applications

  • 相关阅读:
    Jmeter ----关于上传图片接口
    JMeter学习笔记16-如何输出HTML格式的性能测试报告
    Robot Framework课件汇总
    Robot Framework自动化测试(七)--- jybot模式
    Robot Framework自动化测试(六)--- robotremoteserver使用
    Robot Framework自动化测试(四)--- 分层思想
    Robot Framework自动化测试(五)--- 开发系统关键字
    Robot Framework自动化测试(二)---元素定位
    威睿虚拟机 VMware Workstation Pro 15.1.0 中文版 + 注册机
    我眼中的java线程池实现原理
  • 原文地址:https://www.cnblogs.com/lindexi/p/12086599.html
Copyright © 2011-2022 走看看