NativeMethods.cs 9.5 KB

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