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

2018-11-13-WPF-禁用实时触摸的更多相关文章

  1. WPF 禁用实时触摸

    原文:WPF 禁用实时触摸 微软想把 WPF 作为 win7 的触摸好用的框架,所以微软做了很多特殊的兼容.为了获得真实的触摸消息,微软提供了 OnStylusDown, OnStylusUp, 和 ...

  2. 2018.11.13 N4010A 通信设置

    设置电脑之IP地址及Subnet mask.      IP address: 192.168.1.2      Subnet mask: 255.255.255.0, 其它选项为默认. 然后点击OK ...

  3. 2018.11.13 Hibernate 中数据库查询中的Criteria查询实例

    Criteria是面向对象的无语句查询 Demo.java package com.legend.b_criteria; import java.util.List; import org.hiber ...

  4. 2019-11-29-WPF-禁用实时触摸

    原文:2019-11-29-WPF-禁用实时触摸 title author date CreateTime categories WPF 禁用实时触摸 lindexi 2019-11-29 10:20 ...

  5. ASP.NET Boilerplate 学习 AspNet Core2 浏览器缓存使用 c#基础,单线程,跨线程访问和线程带参数 wpf 禁用启用webbroswer右键菜单 EF Core 2.0使用MsSql/MySql实现DB First和Code First ASP.NET Core部署到Windows IIS QRCode.js:使用 JavaScript 生成

    ASP.NET Boilerplate 学习   1.在http://www.aspnetboilerplate.com/Templates 网站下载ABP模版 2.解压后打开解决方案,解决方案目录: ...

  6. OI生涯回忆录 2018.11.12~2019.4.15

    上一篇:OI生涯回忆录 2017.9.10~2018.11.11 一次逆风而行的成功,是什么都无法代替的 ………… 历经艰难 我还在走着 一 NOIP之后,全机房开始了省选知识的自学. 动态DP,LC ...

  7. WPF 插拔触摸设备触摸失效

    原文:WPF 插拔触摸设备触摸失效 最近使用 WPF 程序,在不停插拔触摸设备会让 WPF 程序触摸失效.通过分析 WPF 源代码可以找到 WPF 触摸失效的原因. 在 Windows 会将所有的 H ...

  8. iOS app提交审核 11.13条款问题

    今年开年到现在.提交app应用一直招拒,这个问题我想不明白,感觉就是一个坑.所以贴出来给大家看看. 发件人 Apple11.13 - Apps that link to external mechan ...

  9. China Intelligent Office Summit(2018.11.21)

    时间:2018.11.21地点:中关村软件园国际会议中心

随机推荐

  1. day39 10-Spring的AOP:基于AspectJ的切点定义

    切点是我们真正应用在哪些方法上,增强的那些方法上,就是add().update()和find().delete()是没用的.没用的话就是这三个方法.为什么要定义一个切点呢? 所以可以直接在切面中定义一 ...

  2. python 正则表达式语法

  3. Linux中的库

    一.基本概念 1.1.什么是库        在 windows 平台和 linux 平台下都大量存在着库. 本质上来说库是一种可执行的二进制代码(但不可以独立执行),可以被操作系统载入内存执行. 由 ...

  4. python爬虫:一些爬虫常用的技巧

    1.基本抓取网页 get方法 import urllib2 url = "http://www.baidu.com" response = urllib2.urlopen(url) ...

  5. oralce update操作

    1.基本语法:update  表名 set 列名=表达式 [列名=表达式. . . ] where 条件 2.使用的注意事项: v  UPDATE语法可以用新值更新原有表行中的各列 把zs的性别改为女 ...

  6. core文件相关

    1:当一个程序崩溃时,在进程当前工作目录的core文件中复制了该进程的存储图像.core文件仅仅是一个内存映象(同时加上调试信息),主要是用来调试的. 当程序接收到以下UNIX信号会产生core文件: ...

  7. LeetCode108 Convert Sorted Array to Binary Search Tree

    Given an array where elements are sorted in ascending order, convert it to a height balanced BST. (M ...

  8. This cache store does not support tagging.

    用户权限管理系统 https://github.com/Zizaco/entrust 再添加角色的时候... 报了一个错.. BadMethodCallException in Repository. ...

  9. Android 整合实现简单易用、功能强大的RecyclerView

    之前总是会有人在一些开发群里问,有木有比较好使且功能强大些的RecyclerVew,比如支持下来刷新,加载更多等,还有人在问,如何为RecyclerView添加分割线,尤其是如何为网格布局添加分割线? ...

  10. @codeforces - 1096G@ Lucky Tickets

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 已知一个数(允许前导零)有 n 位(n 为偶数),并知道组成这个 ...