NativeMethods.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Runtime.InteropServices;
  6. using System.Text;
  7. namespace HOZProject
  8. {
  9. /// <summary>
  10. /// Class NativeMethods.
  11. /// </summary>
  12. internal class NativeMethods
  13. {
  14. /// <summary>
  15. /// Enum ComboBoxButtonState
  16. /// </summary>
  17. public enum ComboBoxButtonState
  18. {
  19. /// <summary>
  20. /// The state system none
  21. /// </summary>
  22. STATE_SYSTEM_NONE,
  23. /// <summary>
  24. /// The state system invisible
  25. /// </summary>
  26. STATE_SYSTEM_INVISIBLE = 32768,
  27. /// <summary>
  28. /// The state system pressed
  29. /// </summary>
  30. STATE_SYSTEM_PRESSED = 8
  31. }
  32. /// <summary>
  33. /// Struct RECT
  34. /// </summary>
  35. public struct RECT
  36. {
  37. /// <summary>
  38. /// The left
  39. /// </summary>
  40. public int Left;
  41. /// <summary>
  42. /// The top
  43. /// </summary>
  44. public int Top;
  45. /// <summary>
  46. /// The right
  47. /// </summary>
  48. public int Right;
  49. /// <summary>
  50. /// The bottom
  51. /// </summary>
  52. public int Bottom;
  53. /// <summary>
  54. /// Gets the rect.
  55. /// </summary>
  56. /// <value>The rect.</value>
  57. public Rectangle Rect
  58. {
  59. get
  60. {
  61. return new Rectangle(this.Left, this.Top, this.Right - this.Left, this.Bottom - this.Top);
  62. }
  63. }
  64. /// <summary>
  65. /// Gets the size.
  66. /// </summary>
  67. /// <value>The size.</value>
  68. public Size Size
  69. {
  70. get
  71. {
  72. return new Size(this.Right - this.Left, this.Bottom - this.Top);
  73. }
  74. }
  75. /// <summary>
  76. /// Initializes a new instance of the <see cref="RECT" /> struct.
  77. /// </summary>
  78. /// <param name="left">The left.</param>
  79. /// <param name="top">The top.</param>
  80. /// <param name="right">The right.</param>
  81. /// <param name="bottom">The bottom.</param>
  82. public RECT(int left, int top, int right, int bottom)
  83. {
  84. this.Left = left;
  85. this.Top = top;
  86. this.Right = right;
  87. this.Bottom = bottom;
  88. }
  89. /// <summary>
  90. /// Initializes a new instance of the <see cref="RECT" /> struct.
  91. /// </summary>
  92. /// <param name="rect">The rect.</param>
  93. public RECT(Rectangle rect)
  94. {
  95. this.Left = rect.Left;
  96. this.Top = rect.Top;
  97. this.Right = rect.Right;
  98. this.Bottom = rect.Bottom;
  99. }
  100. /// <summary>
  101. /// Froms the xywh.
  102. /// </summary>
  103. /// <param name="x">The x.</param>
  104. /// <param name="y">The y.</param>
  105. /// <param name="width">The width.</param>
  106. /// <param name="height">The height.</param>
  107. /// <returns>NativeMethods.RECT.</returns>
  108. public static NativeMethods.RECT FromXYWH(int x, int y, int width, int height)
  109. {
  110. return new NativeMethods.RECT(x, y, x + width, y + height);
  111. }
  112. /// <summary>
  113. /// Froms the rectangle.
  114. /// </summary>
  115. /// <param name="rect">The rect.</param>
  116. /// <returns>NativeMethods.RECT.</returns>
  117. public static NativeMethods.RECT FromRectangle(Rectangle rect)
  118. {
  119. return new NativeMethods.RECT(rect.Left, rect.Top, rect.Right, rect.Bottom);
  120. }
  121. }
  122. /// <summary>
  123. /// Struct PAINTSTRUCT
  124. /// </summary>
  125. public struct PAINTSTRUCT
  126. {
  127. /// <summary>
  128. /// The HDC
  129. /// </summary>
  130. public IntPtr hdc;
  131. /// <summary>
  132. /// The f erase
  133. /// </summary>
  134. public int fErase;
  135. /// <summary>
  136. /// The rc paint
  137. /// </summary>
  138. public NativeMethods.RECT rcPaint;
  139. /// <summary>
  140. /// The f restore
  141. /// </summary>
  142. public int fRestore;
  143. /// <summary>
  144. /// The f inc update
  145. /// </summary>
  146. public int fIncUpdate;
  147. /// <summary>
  148. /// The reserved1
  149. /// </summary>
  150. public int Reserved1;
  151. /// <summary>
  152. /// The reserved2
  153. /// </summary>
  154. public int Reserved2;
  155. /// <summary>
  156. /// The reserved3
  157. /// </summary>
  158. public int Reserved3;
  159. /// <summary>
  160. /// The reserved4
  161. /// </summary>
  162. public int Reserved4;
  163. /// <summary>
  164. /// The reserved5
  165. /// </summary>
  166. public int Reserved5;
  167. /// <summary>
  168. /// The reserved6
  169. /// </summary>
  170. public int Reserved6;
  171. /// <summary>
  172. /// The reserved7
  173. /// </summary>
  174. public int Reserved7;
  175. /// <summary>
  176. /// The reserved8
  177. /// </summary>
  178. public int Reserved8;
  179. }
  180. /// <summary>
  181. /// Struct ComboBoxInfo
  182. /// </summary>
  183. public struct ComboBoxInfo
  184. {
  185. /// <summary>
  186. /// The cb size
  187. /// </summary>
  188. public int cbSize;
  189. /// <summary>
  190. /// The rc item
  191. /// </summary>
  192. public NativeMethods.RECT rcItem;
  193. /// <summary>
  194. /// The rc button
  195. /// </summary>
  196. public NativeMethods.RECT rcButton;
  197. /// <summary>
  198. /// The state button
  199. /// </summary>
  200. public NativeMethods.ComboBoxButtonState stateButton;
  201. /// <summary>
  202. /// The HWND combo
  203. /// </summary>
  204. public IntPtr hwndCombo;
  205. /// <summary>
  206. /// The HWND edit
  207. /// </summary>
  208. public IntPtr hwndEdit;
  209. /// <summary>
  210. /// The HWND list
  211. /// </summary>
  212. public IntPtr hwndList;
  213. }
  214. /// <summary>
  215. /// The wm paint
  216. /// </summary>
  217. public const int WM_PAINT = 15;
  218. /// <summary>
  219. /// The wm setredraw
  220. /// </summary>
  221. public const int WM_SETREDRAW = 11;
  222. /// <summary>
  223. /// The false
  224. /// </summary>
  225. public static readonly IntPtr FALSE = IntPtr.Zero;
  226. /// <summary>
  227. /// The true
  228. /// </summary>
  229. public static readonly IntPtr TRUE = new IntPtr(1);
  230. /// <summary>
  231. /// Gets the ComboBox information.
  232. /// </summary>
  233. /// <param name="hwndCombo">The HWND combo.</param>
  234. /// <param name="info">The information.</param>
  235. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
  236. [DllImport("user32.dll")]
  237. public static extern bool GetComboBoxInfo(IntPtr hwndCombo, ref NativeMethods.ComboBoxInfo info);
  238. /// <summary>
  239. /// Gets the window rect.
  240. /// </summary>
  241. /// <param name="hwnd">The HWND.</param>
  242. /// <param name="lpRect">The lp rect.</param>
  243. /// <returns>System.Int32.</returns>
  244. [DllImport("user32.dll")]
  245. public static extern int GetWindowRect(IntPtr hwnd, ref NativeMethods.RECT lpRect);
  246. /// <summary>
  247. /// Begins the paint.
  248. /// </summary>
  249. /// <param name="hWnd">The h WND.</param>
  250. /// <param name="ps">The ps.</param>
  251. /// <returns>IntPtr.</returns>
  252. [DllImport("user32.dll")]
  253. public static extern IntPtr BeginPaint(IntPtr hWnd, ref NativeMethods.PAINTSTRUCT ps);
  254. /// <summary>
  255. /// Ends the paint.
  256. /// </summary>
  257. /// <param name="hWnd">The h WND.</param>
  258. /// <param name="ps">The ps.</param>
  259. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
  260. [DllImport("user32.dll")]
  261. public static extern bool EndPaint(IntPtr hWnd, ref NativeMethods.PAINTSTRUCT ps);
  262. /// <summary>
  263. /// Sends the message.
  264. /// </summary>
  265. /// <param name="hWnd">The h WND.</param>
  266. /// <param name="msg">The MSG.</param>
  267. /// <param name="wParam">The w parameter.</param>
  268. /// <param name="lParam">The l parameter.</param>
  269. [DllImport("user32.dll")]
  270. public static extern void SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
  271. }
  272. }