TouchWin32.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Uni_Trend.MSO7000X.Touch
  8. {
  9. /// <summary>
  10. /// Touch相关的Win32的函数及常量
  11. /// </summary>
  12. public static class TouchWin32
  13. {
  14. [StructLayout(LayoutKind.Sequential)]
  15. public struct TOUCHINPUT
  16. {
  17. public int x; /*The x-coordinate (horizontal point) of the touch input*/
  18. public int y; /*The y-coordinate (horizontal point) of the touch input*/
  19. public IntPtr hSource; /*A device handle for the source input device*/
  20. public int dwID; /*A touch point identifier that distinguishes a particular touch input*/
  21. public int dwFlags; /*A set of bit flags that specify various aspects of touch point press, release, and motion*/
  22. public int dwMask; /*A set of bit flags that specify which of the optional fields in the structure contain valid values.*/
  23. public int dwTime; /*The time stamp for the event, in milliseconds.*/
  24. public IntPtr dwExtraInfo; /*An additional value associated with the touch event.*/
  25. public int cxContact; /*The width of the touch contact area in hundredths of a pixel in physical screen coordinates.*/
  26. public int cyContact; /*The height of the touch contact area in hundredths of a pixel in physical screen coordinates.*/
  27. }
  28. /// <summary>
  29. /// _IManipulationEvents的ManipulationStarted接口回调函数类型
  30. /// <param name="X">x coordiante of the initial point of manipulation(1/100 of pixel)</param>
  31. /// <param name="Y">y coordiante of the initial point of manipulation(1/100 of pixel)</param>
  32. /// </summary>
  33. public delegate void OnManipulationStartedDelegate(
  34. float x,
  35. float y);
  36. /// <summary>
  37. /// _IManipulationEvents的ManipulationDelta接口回调函数类型
  38. /// <param name="X">x coordiante of the initial point of manipulation(1/100 of pixel)</param>
  39. /// <param name="Y">y coordiante of the initial point of manipulation(1/100 of pixel)</param>
  40. /// <param name="translationDeltaX">shift of the x-coordinate (1/100 of pixel)</param>
  41. /// <param name="translationDeltaY">shift of the y-coordinate (1/100 of pixel)</param>
  42. /// <param name="scaleDelta">scale factor (zoom in/out)</param>
  43. /// <param name="expansionDelta">the current rate of scale change</param>
  44. /// <param name="rotationDelta">rotation angle in radians</param>
  45. /// <param name="cumulativeTranslationX">cumulative shift of x-coordinate (1/100 of pixel)</param>
  46. /// <param name="cumulativeTranslationY">cumulative shift of y-coordinate (1/100 of pixel)</param>
  47. /// <param name="cumulativeScale">cumulative scale factor (zoom in/out)</param>
  48. /// <param name="cumulativeExpansion">cumulative rate of scale change</param>
  49. /// <param name="cumulativeRotation">cumulative rotation angle in radians</param>
  50. /// </summary>
  51. public delegate void OnManipulationDeltaDelegate(
  52. float x,
  53. float y,
  54. float translationDeltaX,
  55. float translationDeltaY,
  56. float scaleDelta,
  57. float expansionDelta,
  58. float rotationDelta,
  59. float cumulativeTranslationX,
  60. float cumulativeTranslationY,
  61. float cumulativeScale,
  62. float cumulativeExpansion,
  63. float cumulativeRotation);
  64. /// <summary>
  65. /// _IManipulationEvents的ManipulationCompleted接口回调函数类型
  66. /// <param name="X">x coordiante of the initial point of manipulation(1/100 of pixel)</param>
  67. /// <param name="Y">y coordiante of the initial point of manipulation(1/100 of pixel)</param>
  68. /// <param name="cumulativeTranslationX">cumulative shift of x-coordinate (1/100 of pixel)</param>
  69. /// <param name="cumulativeTranslationY">cumulative shift of y-coordinate (1/100 of pixel)</param>
  70. /// <param name="cumulativeScale">cumulative scale factor (zoom in/out)</param>
  71. /// <param name="cumulativeExpansion">cumulative rate of scale change</param>
  72. /// <param name="cumulativeRotation">cumulative rotation angle in radians</param>
  73. /// </summary>
  74. public delegate void OnManipulationCompletedDelegate(
  75. float x,
  76. float y,
  77. float cumulativeTranslationX,
  78. float cumulativeTranslationY,
  79. float cumulativeScale,
  80. float cumulativeExpansion,
  81. float cumulativeRotation);
  82. //用于TOUCHINPUT中dwFlags的取值
  83. public const int TOUCHEVENTF_DOWN = 0x2;
  84. public const int TOUCHEVENTF_UP = 0x4;
  85. public const int TOUCHEVENTF_MOVE = 0x1;
  86. //触摸相关的C++库的路径
  87. const string ManipulationHelperPath = "Uni-Trend.MSO7000X.Touch.ManupulationHelper.dll";
  88. /// <summary>
  89. /// 注册一个窗口(控件)具有触摸功能
  90. /// <param name="formHandle">窗口(控件)的句柄</param>
  91. /// <param name="msCallback">操作开始的回调函数(需要OnManipulationStartedDelegate转化来)</param>
  92. /// <param name="mdCallback">操作过程变化的回调函数(需要OnManipulationDeltaDelegate转化来)</param>
  93. /// <param name="mcCallback">操作结束的回调函数(需要OnManipulationCompletedDelegate转化来)</param>
  94. /// <return>操作帮助器</return>
  95. /// </summary>
  96. [DllImport(ManipulationHelperPath, EntryPoint = "RegisterWnd")]
  97. public static extern IntPtr RegisterWnd(
  98. IntPtr hWnd,
  99. IntPtr msCallback,
  100. IntPtr mdCallback,
  101. IntPtr mcCallBack);
  102. /// <summary>
  103. /// 把TouchDown类型的触摸消息拿到ManipulationHelper里的IManipulationProcessor处理
  104. /// <param name="helper">触摸功能帮助器</param>
  105. /// <param name="manipulatorId">Touch消息对应的操作ID</param>
  106. /// <param name="x">Touch消息触点的X坐标(屏幕坐标系)</param>
  107. /// <param name="y">触摸功能帮助器</param>
  108. /// <returns></returns>
  109. [DllImport(ManipulationHelperPath, EntryPoint = "ProcessDown")]
  110. public static extern void ProcessDown(
  111. IntPtr helper,
  112. int manipulatorId,
  113. float x,
  114. float y);
  115. // 把TouchMove类型的触摸消息拿到ManipulationHelper里的IManipulationProcessor处理
  116. [DllImport(ManipulationHelperPath, EntryPoint = "ProcessMove")]
  117. public static extern void ProcessMove(
  118. IntPtr helper,
  119. int manipulatorId,
  120. float x,
  121. float y);
  122. // 把TouchUp类型的触摸消息拿到ManipulationHelper里的IManipulationProcessor处理
  123. [DllImport(ManipulationHelperPath, EntryPoint = "ProcessUp")]
  124. public static extern void ProcessUp(
  125. IntPtr helper,
  126. int manipulatorId,
  127. float x,
  128. float y);
  129. /// <summary>
  130. /// 获取当前触摸点集信息
  131. /// </summary>
  132. /// <param name="hTouchInput">Touch信息指针</param>
  133. /// <param name="cInputs">Touch触点的个数</param>
  134. /// <param name="pInputs">接收信息的数组</param>
  135. /// <param name="cbSize">单个数组成员的大小</param>
  136. /// <returns></returns>
  137. [DllImport("user32")]
  138. public static extern bool GetTouchInputInfo(IntPtr hTouchInput, int cInputs, [In, Out] TOUCHINPUT[] pInputs, int cbSize);
  139. /// <summary>
  140. /// 关闭当前触摸点集信息
  141. /// </summary>
  142. /// <param name="hTouchInfo">Touch信息指针</param>
  143. /// <returns></returns>
  144. [DllImport("user32")]
  145. public static extern bool CloseTouchInputHandle(IntPtr hTouchInfo);
  146. }
  147. }