Windows Touch 便笺簿的 C# 示例 (MTScratchpadWMTouchCS)

 

本节介绍 Windows Touch 便笺簿的 C# 示例。

Windows Touch 便笺簿的 C# 示例演示如何使用 Windows Touch 消息在窗口上绘制触控点的踪迹。主手指(最先放置到数字化器上的手指)的踪迹是用黑色绘制的。辅助手指的踪迹用其他六种颜色绘制:红色、绿色、蓝色、蓝绿色、洋红色和黄色。下图演示了应用程序在运行时的可能外观。

在此示例中,将创建一个具有触控功能的表单来处理 WM_TOUCH 消息。继承此表单以便在便笺簿应用程序上启用 Windows Touch。当WM_TOUCH 消息传入到此表单时,这些消息将被解释为点并添加到笔画集合中。然后向 Graphics 对象呈现笔画集合。以下代码演示具有触控功能的表单如何注册自身以处理 WM_TOUCH 消息,以及它如何处理 WM_TOUCH 消息。

 
 
        private void OnLoadHandler(Object sender, EventArgs e)
{
try
{
// Registering the window for multi-touch, using the default settings.
// p/invoking into user32.dll
if (!RegisterTouchWindow(this.Handle, 0))
{
Debug.Print("ERROR: Could not register window for multi-touch");
}
}
catch (Exception exception)
{
Debug.Print("ERROR: RegisterTouchWindow API not available");
Debug.Print(exception.ToString());
MessageBox.Show("RegisterTouchWindow API not available", "MTScratchpadWMTouch ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0);
}
}
(...)
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
protected override void WndProc(ref Message m)
{
// Decode and handle WM_TOUCH message.
bool handled;
switch (m.Msg)
{
case WM_TOUCH:
handled = DecodeTouch(ref m);
break;
default:
handled = false;
break;
} // Call parent WndProc for default message processing.
base.WndProc(ref m); if (handled)
{
// Acknowledge event if handled.
m.Result = new System.IntPtr(1);
}
}

以下代码演示如何解释 Windows Touch 消息,以及如何将数据添加到笔画集合中。

 
 
        private bool DecodeTouch(ref Message m)
{
// More than one touchinput may be associated with a touch message,
// so an array is needed to get all event information.
int inputCount = LoWord(m.WParam.ToInt32()); // Number of touch inputs, actual per-contact messages TOUCHINPUT[] inputs; // Array of TOUCHINPUT structures
inputs = new TOUCHINPUT[inputCount]; // Allocate the storage for the parameters of the per-contact messages // Unpack message parameters into the array of TOUCHINPUT structures, each
// representing a message for one single contact.
if (!GetTouchInputInfo(m.LParam, inputCount, inputs, touchInputSize))
{
// Get touch info failed.
return false;
} // For each contact, dispatch the message to the appropriate message
// handler.
bool handled = false; // Boolean, is message handled
for (int i = 0; i < inputCount; i++)
{
TOUCHINPUT ti = inputs[i]; // Assign a handler to this message.
EventHandler<WMTouchEventArgs> handler = null; // Touch event handler
if ((ti.dwFlags & TOUCHEVENTF_DOWN) != 0)
{
handler = Touchdown;
}
else if ((ti.dwFlags & TOUCHEVENTF_UP) != 0)
{
handler = Touchup;
}
else if ((ti.dwFlags & TOUCHEVENTF_MOVE) != 0)
{
handler = TouchMove;
} // Convert message parameters into touch event arguments and handle the event.
if (handler != null)
{
// Convert the raw touchinput message into a touchevent.
WMTouchEventArgs te = new WMTouchEventArgs(); // Touch event arguments // TOUCHINFO point coordinates and contact size is in 1/100 of a pixel; convert it to pixels.
// Also convert screen to client coordinates.
te.ContactY = ti.cyContact/100;
te.ContactX = ti.cxContact/100;
te.Id = ti.dwID;
{
Point pt = PointToClient(new Point(ti.x/100, ti.y/100));
te.LocationX = pt.X;
te.LocationY = pt.Y;
}
te.Time = ti.dwTime;
te.Mask = ti.dwMask;
te.Flags = ti.dwFlags; // Invoke the event handler.
handler(this, te); // Mark this event as handled.
handled = true;
}
} CloseTouchInputHandle(m.LParam); return handled;
}
}

以下代码演示如何呈现笔画集合。

 
 
        public void Draw(Graphics graphics)
{
if ((points.Count < 2) || (graphics == null))
{
return;
} Pen pen = new Pen(color, penWidth);
graphics.DrawLines(pen, (Point[]) points.ToArray(typeof(Point)));
}

以下代码演示各个笔画对象如何使用 Graphics 对象呈现自己。

 
 
        public void Draw(Graphics graphics)
{
if(points.Count < 2 || graphics == null)
{
return;
} Pen pen = new Pen(color, penWidth);
graphics.DrawLines(pen, (Point[]) points.ToArray(typeof(Point)));
}

Windows Touch 便笺簿的的更多相关文章

  1. Windbg Scratch Pad(便笺簿)窗口的使用

    “便笺簿”窗口是一个剪贴板,您可以在其中键入和保存文本. 打开便笺簿 通过菜单View--->Scratch Pad 通过快捷键Alt+8 通过工具栏 使用便笺簿 用上面的方式打开的窗口如下: ...

  2. simulate windows touch input

    更多信息请参考页面http://social.technet.microsoft.com/wiki/contents/articles/6460.simulating-touch-input-in-w ...

  3. XP之后Windows的一些变化

    看到很多Windows开发人员,尤其是C++程序员思维还是停留在XP操作系统,当然根据工作是否需要新知识 ,这本身没有错.但是实际上Vista之后的Win7, 再之后的Win8 ,Windows已经发 ...

  4. Windows api 函数全部列表 (未完成)

    网上找了很久,发现没有完整版的,msdn上面有,但是不方便查阅,所以想自己整理一下:由于工程量过于庞大,希望大家共同完成.MSDN:http://msdn.microsoft.com/en-us/li ...

  5. iOS数据持久化-OC

    沙盒详解 1.IOS沙盒机制 IOS应用程序只能在为该改程序创建的文件系统中读取文件,不可以去其它地方访问,此区域被成为沙盒,所以所有的非代码文件都要保存在此,例如图像,图标,声音,映像,属性列表,文 ...

  6. iOS-数据持久化-CoreData

    CoreData详解 介绍: 在Cocoa环境下,如果你想使用数据库(如sqlite),你可以使用sql语句的方式通过相关的工具类进行数据库的直接操作.当然你也可以通过别人封装之后的一些简单框架,使得 ...

  7. 很多人很想知道怎么扫一扫二维码就能打开网站,就能添加联系人,就能链接wifi,今天说下这些格式,明天做个demo

    有些功能部分手机不能使用,网站,通讯录,wifi基本上每个手机都可以使用. 在看之前你可以扫一扫下面几个二维码先看看效果: 1.二维码生成 网址 (URL) 包含网址的 二维码生成 是大家平时最常接触 ...

  8. c# 元组Tuple

    Tuple类型像一个口袋,在出门前可以把所需的任何东西一股脑地放在里面.您可以将钥匙.驾驶证.便笺簿和钢笔放在口袋里,您的口袋是存放各种东西的收集箱.C# 4.0引入的一个新特性 Tuple类型与口袋 ...

  9. .NET Framework 4.0之Tuple(元组)

    Tuple,是函数式编程的概念之一,早见于Elang.F#等动态语言.Tuple类型像一个口袋,在出门前可以把所需的任何东西一股脑地放在里面.您可以将钥匙.驾驶证.便笺簿和钢笔放在口袋里,您的口袋是存 ...

随机推荐

  1. cocoapods最新使用

    1.首先用淘宝的Ruby镜像来访问CocoaPods,打开终端输入以下命令: (1)gem sources --remove http://ruby.gems.org/   (移除现有Ruby默认源) ...

  2. 自编码器(autoencoder)

    今天我们会来聊聊用神经网络如何进行非监督形式的学习. 也就是 autoencoder, 自编码. 压缩与解压 有一个神经网络, 它在做的事情是 接收一张图片, 然后 给它打码, 最后 再从打码后的图片 ...

  3. 从springmvc启动日志学习

    javaee标准中,tomcat等web容器启动时走web.xml 先将各种contex-param 放到servletcontxt中变成parameter,然后开始启动容器,容器对外提供了liste ...

  4. linux下tomcat的配置及项目的部署流程

    Java的安装配置 1. 在/etc/profile文件中配置相应的信息(如下) export JAVA_HOME=/usr/java/jdk1.6.0_20 export JRE_HOME=/usr ...

  5. 【leetcode刷题笔记】Permutation Sequence

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  6. 转的es6 =>函数

    原文地址 箭头函数=>无疑是ES6中最受关注的一个新特性了,通过它可以简写 function 函数表达式,你也可以在各种提及箭头函数的地方看到这样的观点--"=> 就是一个新的 ...

  7. 【Java】-BigInteger大数类的使用【超强Java大数模板 总结】

    Scanner cin = new Scanner(new BufferedInputStream(System.in)); 这样定义Scanner类的对象读入数据可能会快一些! 参考这个博客继续补充 ...

  8. EntityFramework 学习 一 Lazy Loading 1

    延迟加载:延迟加载相关的数据 using (var ctx = new SchoolDBEntities()) { //Loading students only IList<Student&g ...

  9. Stanford Log-linear Part-Of-Speech Tagger标记含义

    Stanford Log-linear Part-Of-Speech Tagger标记含义 英文词性标记名称缩写的含义: 使用的是宾州树库的tag集合,具体含义和举例如下表: Tag Descript ...

  10. Windows- 改变cmd控制台默认显示编码

    在中国的电脑会要求兼容gbk编码,所以微软进入中国市场也顺应中国的要求,其中最明显的就是在cmd上默认的显示就是GBK .当开发人员在运行一些有打印中文的程序时,由于编码采用国际兼容版本的utf_8等 ...