BaseFormWin32.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Drawing;
  4. using System.Globalization;
  5. namespace HXX.Scanner.Client.Base
  6. {
  7. internal static class BaseFormWin32
  8. {
  9. public const int MF_REMOVE = 0x1000;
  10. public const int SC_RESTORE = 0xF120; //还原
  11. public const int SC_MOVE = 0xF010; //移动
  12. public const int SC_SIZE = 0xF000; //大小
  13. public const int SC_MINIMIZE = 0xF020; //最小化
  14. public const int SC_MAXIMIZE = 0xF030; //最大化
  15. public const int SC_CLOSE = 0xF060; //关闭
  16. public const int WM_SYSCOMMAND = 0x0112;
  17. public const int WM_COMMAND = 0x0111;
  18. public const int GW_HWNDFIRST = 0;
  19. public const int GW_HWNDLAST = 1;
  20. public const int GW_HWNDNEXT = 2;
  21. public const int GW_HWNDPREV = 3;
  22. public const int GW_OWNER = 4;
  23. public const int GW_CHILD = 5;
  24. public const int WM_NCCALCSIZE = 0x83;
  25. public const int WM_WINDOWPOSCHANGING = 0x46;
  26. public const int WM_PAINT = 0xF;
  27. public const int WM_CREATE = 0x1;
  28. public const int WM_NCCREATE = 0x81;
  29. public const int WM_NCPAINT = 0x85;
  30. public const int WM_PRINT = 0x317;
  31. public const int WM_DESTROY = 0x2;
  32. public const int WM_SHOWWINDOW = 0x18;
  33. public const int WM_SHARED_MENU = 0x1E2;
  34. public const int HC_ACTION = 0;
  35. public const int WH_CALLWNDPROC = 4;
  36. public const int GWL_WNDPROC = -4;
  37. public const int WS_SYSMENU = 0x80000;
  38. public const int WS_SIZEBOX = 0x40000;
  39. public const int WS_MAXIMIZEBOX = 0x10000;
  40. public const int WS_MINIMIZEBOX = 0x20000;
  41. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  42. public static extern int SetWindowLong(IntPtr hWnd, int Index, int Value);
  43. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  44. public static extern int GetWindowLong(IntPtr hWnd, int Index);
  45. [DllImport("user32")]
  46. public static extern IntPtr GetSystemMenu(IntPtr hwnd, int flag);
  47. [DllImport("user32")]
  48. public static extern int TrackPopupMenu(int hMenu, int wFlags, int x, int y, int nReserved, IntPtr hwnd, int lprc);
  49. [DllImport("user32")]
  50. public static extern int SendMessage(IntPtr hwnd, int msg, int wp, int lp);
  51. [DllImport("user32")]
  52. public static extern int ReleaseCapture();
  53. [DllImport("gdi32.dll")]
  54. public static extern int CreateRoundRectRgn(int x1, int y1, int x2, int y2, int x3, int y3);
  55. [DllImport("user32.dll")]
  56. public static extern int SetWindowRgn(IntPtr hwnd, int hRgn, Boolean bRedraw);
  57. public const int CS_DROPSHADOW = 0x20000;
  58. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  59. public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
  60. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  61. public static extern int GetClassLong(IntPtr hwnd, int nIndex);
  62. public struct MENUINFO
  63. {
  64. public int cbSize;
  65. public uint fMask;
  66. public int dwStyle;
  67. public int cyMax;
  68. public int hbrBack;
  69. public int dwContextHelpID;
  70. public int dwMenuData;
  71. }
  72. [DllImport("gdi32")]
  73. public static extern int CreatePatternBrush(int hBitmap);
  74. [DllImport("user32")]
  75. public static extern int SetMenuInfo(IntPtr hMenu, ref MENUINFO mi);
  76. [DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Auto)]
  77. public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
  78. [DllImport("kernel32.dll")]
  79. public static extern bool SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);
  80. public const int GCW_ATOM = -32;
  81. public const int GCL_CBCLSEXTRA = -20;
  82. public const int GCL_CBWNDEXTRA = -18;
  83. public const int GCL_HBRBACKGROUND = -10;
  84. public const int GCL_HCURSOR = -12;
  85. public const int GCL_HICON = -14;
  86. public const int GCL_HMODULE = -16;
  87. public const int GCL_MENUNAME = -8;
  88. public const int GCL_STYLE = -26;
  89. public const int GCL_WNDPROC = -24;
  90. [DllImport("user32", EntryPoint = "GetClassLong")]
  91. public static extern int GetClassLong(int hwnd, int nIndex);
  92. [DllImport("user32", EntryPoint = "SetClassLong")]
  93. public static extern int SetClassLong(int hwnd, int nIndex, int dwNewLong);
  94. public const int WM_SETREDRAW = 0x000B;
  95. public const int WM_USER = 0x400;
  96. public const int EM_GETEVENTMASK = (WM_USER + 59);
  97. public const int EM_SETEVENTMASK = (WM_USER + 69);
  98. [DllImport("user32.dll")]
  99. public extern static bool LockWindowUpdate(IntPtr hWndLock);
  100. [DllImport("User32.dll", CharSet = CharSet.Auto)]
  101. public static extern IntPtr GetWindowDC(IntPtr handle);
  102. [DllImport("User32.dll", CharSet = CharSet.Auto)]
  103. public static extern IntPtr ReleaseDC(IntPtr handle, IntPtr hDC);
  104. [DllImport("Gdi32.dll", CharSet = CharSet.Auto)]
  105. public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
  106. [DllImport("User32.dll", CharSet = CharSet.Auto)]
  107. public static extern int GetClassName(IntPtr hwnd, char[] className, int maxCount);
  108. [DllImport("User32.dll", CharSet = CharSet.Auto)]
  109. public static extern IntPtr GetWindow(IntPtr hwnd, int uCmd);
  110. [DllImport("User32.dll", CharSet = CharSet.Auto)]
  111. public static extern bool IsWindowVisible(IntPtr hwnd);
  112. [DllImport("user32", CharSet = CharSet.Auto)]
  113. public static extern int GetClientRect(IntPtr hwnd, ref RECT lpRect);
  114. [DllImport("user32", CharSet = CharSet.Auto)]
  115. public static extern int GetClientRect(IntPtr hwnd, [In, Out] ref Rectangle rect);
  116. [DllImport("user32", CharSet = CharSet.Auto)]
  117. public static extern bool MoveWindow(IntPtr hwnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
  118. [DllImport("user32", CharSet = CharSet.Auto)]
  119. public static extern bool UpdateWindow(IntPtr hwnd);
  120. [DllImport("user32", CharSet = CharSet.Auto)]
  121. public static extern bool InvalidateRect(IntPtr hwnd, ref Rectangle rect, bool bErase);
  122. [DllImport("user32", CharSet = CharSet.Auto)]
  123. public static extern bool ValidateRect(IntPtr hwnd, ref Rectangle rect);
  124. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  125. public static extern bool GetWindowRect(IntPtr hWnd, [In, Out] ref Rectangle rect);
  126. [StructLayout(LayoutKind.Sequential)]
  127. public struct RECT
  128. {
  129. public int Left;
  130. public int Top;
  131. public int Right;
  132. public int Bottom;
  133. }
  134. [StructLayout(LayoutKind.Sequential)]
  135. public struct WINDOWPOS
  136. {
  137. public IntPtr hwnd;
  138. public IntPtr hwndAfter;
  139. public int x;
  140. public int y;
  141. public int cx;
  142. public int cy;
  143. public uint flags;
  144. }
  145. [StructLayout(LayoutKind.Sequential)]
  146. public struct NCCALCSIZE_PARAMS
  147. {
  148. public RECT rgc;
  149. public WINDOWPOS wndpos;
  150. }
  151. [StructLayout(LayoutKind.Sequential)]
  152. public struct tagSCROLLINFO
  153. {
  154. public uint cbSize;
  155. public uint fMask;
  156. public int nMin;
  157. public int nMax;
  158. public uint nPage;
  159. public int nPos;
  160. public int nTrackPos;
  161. }
  162. public enum fnBar
  163. {
  164. SB_HORZ = 0,
  165. SB_VERT = 1,
  166. SB_CTL = 2
  167. }
  168. public enum fMask
  169. {
  170. SIF_ALL,
  171. SIF_DISABLENOSCROLL = 0X0010,
  172. SIF_PAGE = 0X0002,
  173. SIF_POS = 0X0004,
  174. SIF_RANGE = 0X0001,
  175. SIF_TRACKPOS = 0X0008
  176. }
  177. public static int MakeLong(short lowPart, short highPart)
  178. {
  179. return (int)(((ushort)lowPart) | (uint)(highPart << 16));
  180. }
  181. public const int SB_THUMBTRACK = 5;
  182. public const int WM_HSCROLL = 0x114;
  183. public const int WM_VSCROLL = 0x115;
  184. [DllImport("user32.dll", EntryPoint = "GetScrollInfo")]
  185. public static extern bool GetScrollInfo(IntPtr hwnd, int fnBar, ref SCROLLINFO lpsi);
  186. [DllImport("user32.dll", EntryPoint = "SetScrollInfo")]
  187. public static extern int SetScrollInfo(IntPtr hwnd, int fnBar, [In] ref SCROLLINFO lpsi, bool fRedraw);
  188. [DllImport("User32.dll", CharSet = CharSet.Auto, EntryPoint = "SendMessage")]
  189. static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
  190. [DllImport("user32.dll", SetLastError = true)]
  191. public static extern bool PostMessage(IntPtr hWnd, uint Msg, long wParam, int lParam);
  192. public struct SCROLLINFO
  193. {
  194. public uint cbSize;
  195. public uint fMask;
  196. public int nMin;
  197. public int nMax;
  198. public uint nPage;
  199. public int nPos;
  200. public int nTrackPos;
  201. }
  202. public enum ScrollInfoMask
  203. {
  204. SIF_RANGE = 0x1,
  205. SIF_PAGE = 0x2,
  206. SIF_POS = 0x4,
  207. SIF_DISABLENOSCROLL = 0x8,
  208. SIF_TRACKPOS = 0x10,
  209. SIF_ALL = SIF_RANGE + SIF_PAGE + SIF_POS + SIF_TRACKPOS
  210. }
  211. public enum ScrollBarDirection
  212. {
  213. SB_HORZ = 0,
  214. SB_VERT = 1,
  215. SB_CTL = 2,
  216. SB_BOTH = 3
  217. }
  218. [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
  219. public static extern bool GetClientRect(HandleRef hWnd, [In, Out] ref RECT rect);
  220. [StructLayout(LayoutKind.Sequential)]
  221. public class SYSTEMTIME
  222. {
  223. public short wYear;
  224. public short wMonth;
  225. public short wDayOfWeek;
  226. public short wDay;
  227. public short wHour;
  228. public short wMinute;
  229. public short wSecond;
  230. public short wMilliseconds;
  231. public override string ToString()
  232. {
  233. return ("[SYSTEMTIME: " + this.wDay.ToString(CultureInfo.InvariantCulture) + "/" + this.wMonth.ToString(CultureInfo.InvariantCulture) + "/" + this.wYear.ToString(CultureInfo.InvariantCulture) + " " + this.wHour.ToString(CultureInfo.InvariantCulture) + ":" + this.wMinute.ToString(CultureInfo.InvariantCulture) + ":" + this.wSecond.ToString(CultureInfo.InvariantCulture) + "]");
  234. }
  235. }
  236. [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
  237. public class SYSTEMTIMEARRAY
  238. {
  239. public short wYear1;
  240. public short wMonth1;
  241. public short wDayOfWeek1;
  242. public short wDay1;
  243. public short wHour1;
  244. public short wMinute1;
  245. public short wSecond1;
  246. public short wMilliseconds1;
  247. public short wYear2;
  248. public short wMonth2;
  249. public short wDayOfWeek2;
  250. public short wDay2;
  251. public short wHour2;
  252. public short wMinute2;
  253. public short wSecond2;
  254. public short wMilliseconds2;
  255. }
  256. }
  257. }