123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- namespace Uni_Trend.MSO7000X.Touch
- {
- /// <summary>
- /// Touch相关的Win32的函数及常量
- /// </summary>
- public static class TouchWin32
- {
- [StructLayout(LayoutKind.Sequential)]
- public struct TOUCHINPUT
- {
- public int x; /*The x-coordinate (horizontal point) of the touch input*/
- public int y; /*The y-coordinate (horizontal point) of the touch input*/
- public IntPtr hSource; /*A device handle for the source input device*/
- public int dwID; /*A touch point identifier that distinguishes a particular touch input*/
- public int dwFlags; /*A set of bit flags that specify various aspects of touch point press, release, and motion*/
- public int dwMask; /*A set of bit flags that specify which of the optional fields in the structure contain valid values.*/
- public int dwTime; /*The time stamp for the event, in milliseconds.*/
- public IntPtr dwExtraInfo; /*An additional value associated with the touch event.*/
- public int cxContact; /*The width of the touch contact area in hundredths of a pixel in physical screen coordinates.*/
- public int cyContact; /*The height of the touch contact area in hundredths of a pixel in physical screen coordinates.*/
- }
- /// <summary>
- /// _IManipulationEvents的ManipulationStarted接口回调函数类型
- /// <param name="X">x coordiante of the initial point of manipulation(1/100 of pixel)</param>
- /// <param name="Y">y coordiante of the initial point of manipulation(1/100 of pixel)</param>
- /// </summary>
- public delegate void OnManipulationStartedDelegate(
- float x,
- float y);
- /// <summary>
- /// _IManipulationEvents的ManipulationDelta接口回调函数类型
- /// <param name="X">x coordiante of the initial point of manipulation(1/100 of pixel)</param>
- /// <param name="Y">y coordiante of the initial point of manipulation(1/100 of pixel)</param>
- /// <param name="translationDeltaX">shift of the x-coordinate (1/100 of pixel)</param>
- /// <param name="translationDeltaY">shift of the y-coordinate (1/100 of pixel)</param>
- /// <param name="scaleDelta">scale factor (zoom in/out)</param>
- /// <param name="expansionDelta">the current rate of scale change</param>
- /// <param name="rotationDelta">rotation angle in radians</param>
- /// <param name="cumulativeTranslationX">cumulative shift of x-coordinate (1/100 of pixel)</param>
- /// <param name="cumulativeTranslationY">cumulative shift of y-coordinate (1/100 of pixel)</param>
- /// <param name="cumulativeScale">cumulative scale factor (zoom in/out)</param>
- /// <param name="cumulativeExpansion">cumulative rate of scale change</param>
- /// <param name="cumulativeRotation">cumulative rotation angle in radians</param>
- /// </summary>
- public delegate void OnManipulationDeltaDelegate(
- float x,
- float y,
- float translationDeltaX,
- float translationDeltaY,
- float scaleDelta,
- float expansionDelta,
- float rotationDelta,
- float cumulativeTranslationX,
- float cumulativeTranslationY,
- float cumulativeScale,
- float cumulativeExpansion,
- float cumulativeRotation);
- /// <summary>
- /// _IManipulationEvents的ManipulationCompleted接口回调函数类型
- /// <param name="X">x coordiante of the initial point of manipulation(1/100 of pixel)</param>
- /// <param name="Y">y coordiante of the initial point of manipulation(1/100 of pixel)</param>
- /// <param name="cumulativeTranslationX">cumulative shift of x-coordinate (1/100 of pixel)</param>
- /// <param name="cumulativeTranslationY">cumulative shift of y-coordinate (1/100 of pixel)</param>
- /// <param name="cumulativeScale">cumulative scale factor (zoom in/out)</param>
- /// <param name="cumulativeExpansion">cumulative rate of scale change</param>
- /// <param name="cumulativeRotation">cumulative rotation angle in radians</param>
- /// </summary>
- public delegate void OnManipulationCompletedDelegate(
- float x,
- float y,
- float cumulativeTranslationX,
- float cumulativeTranslationY,
- float cumulativeScale,
- float cumulativeExpansion,
- float cumulativeRotation);
- //用于TOUCHINPUT中dwFlags的取值
- public const int TOUCHEVENTF_DOWN = 0x2;
- public const int TOUCHEVENTF_UP = 0x4;
- public const int TOUCHEVENTF_MOVE = 0x1;
- //触摸相关的C++库的路径
- const string ManipulationHelperPath = "Uni-Trend.MSO7000X.Touch.ManupulationHelper.dll";
- /// <summary>
- /// 注册一个窗口(控件)具有触摸功能
- /// <param name="formHandle">窗口(控件)的句柄</param>
- /// <param name="msCallback">操作开始的回调函数(需要OnManipulationStartedDelegate转化来)</param>
- /// <param name="mdCallback">操作过程变化的回调函数(需要OnManipulationDeltaDelegate转化来)</param>
- /// <param name="mcCallback">操作结束的回调函数(需要OnManipulationCompletedDelegate转化来)</param>
- /// <return>操作帮助器</return>
- /// </summary>
- [DllImport(ManipulationHelperPath, EntryPoint = "RegisterWnd")]
- public static extern IntPtr RegisterWnd(
- IntPtr hWnd,
- IntPtr msCallback,
- IntPtr mdCallback,
- IntPtr mcCallBack);
- /// <summary>
- /// 把TouchDown类型的触摸消息拿到ManipulationHelper里的IManipulationProcessor处理
- /// <param name="helper">触摸功能帮助器</param>
- /// <param name="manipulatorId">Touch消息对应的操作ID</param>
- /// <param name="x">Touch消息触点的X坐标(屏幕坐标系)</param>
- /// <param name="y">触摸功能帮助器</param>
- /// <returns></returns>
- [DllImport(ManipulationHelperPath, EntryPoint = "ProcessDown")]
- public static extern void ProcessDown(
- IntPtr helper,
- int manipulatorId,
- float x,
- float y);
- // 把TouchMove类型的触摸消息拿到ManipulationHelper里的IManipulationProcessor处理
- [DllImport(ManipulationHelperPath, EntryPoint = "ProcessMove")]
- public static extern void ProcessMove(
- IntPtr helper,
- int manipulatorId,
- float x,
- float y);
- // 把TouchUp类型的触摸消息拿到ManipulationHelper里的IManipulationProcessor处理
- [DllImport(ManipulationHelperPath, EntryPoint = "ProcessUp")]
- public static extern void ProcessUp(
- IntPtr helper,
- int manipulatorId,
- float x,
- float y);
- /// <summary>
- /// 获取当前触摸点集信息
- /// </summary>
- /// <param name="hTouchInput">Touch信息指针</param>
- /// <param name="cInputs">Touch触点的个数</param>
- /// <param name="pInputs">接收信息的数组</param>
- /// <param name="cbSize">单个数组成员的大小</param>
- /// <returns></returns>
- [DllImport("user32")]
- public static extern bool GetTouchInputInfo(IntPtr hTouchInput, int cInputs, [In, Out] TOUCHINPUT[] pInputs, int cbSize);
- /// <summary>
- /// 关闭当前触摸点集信息
- /// </summary>
- /// <param name="hTouchInfo">Touch信息指针</param>
- /// <returns></returns>
- [DllImport("user32")]
- public static extern bool CloseTouchInputHandle(IntPtr hTouchInfo);
- }
- }
|