FormStyleAPI.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 Y.Utils.WindowsUtils.APIUtils
  8. {
  9. public class FormStyleAPI
  10. {
  11. [StructLayout(LayoutKind.Sequential)]
  12. public struct Size
  13. {
  14. public Int32 cx;
  15. public Int32 cy;
  16. public Size(Int32 x, Int32 y)
  17. {
  18. cx = x;
  19. cy = y;
  20. }
  21. }
  22. [StructLayout(LayoutKind.Sequential, Pack = 1)]
  23. public struct BLENDFUNCTION
  24. {
  25. public byte BlendOp;
  26. public byte BlendFlags;
  27. public byte SourceConstantAlpha;
  28. public byte AlphaFormat;
  29. }
  30. [StructLayout(LayoutKind.Sequential)]
  31. public struct Point
  32. {
  33. public Int32 x;
  34. public Int32 y;
  35. public Point(Int32 x, Int32 y)
  36. {
  37. this.x = x;
  38. this.y = y;
  39. }
  40. }
  41. public const byte AC_SRC_OVER = 0;
  42. public const Int32 ULW_ALPHA = 2;
  43. public const byte AC_SRC_ALPHA = 1;
  44. /// <summary>
  45. /// 从左到右显示
  46. /// </summary>
  47. public const Int32 AW_HOR_POSITIVE = 0x00000001;
  48. /// <summary>
  49. /// 从右到左显示
  50. /// </summary>
  51. public const Int32 AW_HOR_NEGATIVE = 0x00000002;
  52. /// <summary>
  53. /// 从上到下显示
  54. /// </summary>
  55. public const Int32 AW_VER_POSITIVE = 0x00000004;
  56. /// <summary>
  57. /// 从下到上显示
  58. /// </summary>
  59. public const Int32 AW_VER_NEGATIVE = 0x00000008;
  60. /// <summary>
  61. /// 若使用了AW_HIDE标志,则使窗口向内重叠,即收缩窗口;否则使窗口向外扩展,即展开窗口
  62. /// </summary>
  63. public const Int32 AW_CENTER = 0x00000010;
  64. /// <summary>
  65. /// 隐藏窗口,缺省则显示窗口
  66. /// </summary>
  67. public const Int32 AW_HIDE = 0x00010000;
  68. /// <summary>
  69. /// 激活窗口。在使用了AW_HIDE标志后不能使用这个标志
  70. /// </summary>
  71. public const Int32 AW_ACTIVATE = 0x00020000;
  72. /// <summary>
  73. /// 使用滑动类型。缺省则为滚动动画类型。当使用AW_CENTER标志时,这个标志就被忽略
  74. /// </summary>
  75. public const Int32 AW_SLIDE = 0x00040000;
  76. /// <summary>
  77. /// 透明度从高到低
  78. /// </summary>
  79. public const Int32 AW_BLEND = 0x00080000;
  80. #region MyRegion
  81. public const int WM_ERASEBKGND = 0x0014;
  82. public const int WM_LBUTTONDOWN = 0x0201;
  83. public const int WM_LBUTTONUP = 0x0202;
  84. public const int WM_LBUTTONDBLCLK = 0x0203;
  85. public const int WM_WINDOWPOSCHANGING = 0x46;
  86. public const int WM_PAINT = 0xF;
  87. public const int WM_CREATE = 0x0001;
  88. public const int WM_ACTIVATE = 0x0006;
  89. public const int WM_NCCREATE = 0x0081;
  90. public const int WM_NCCALCSIZE = 0x0083;
  91. public const int WM_NCPAINT = 0x0085;
  92. public const int WM_NCACTIVATE = 0x0086;
  93. public const int WM_NCLBUTTONDOWN = 0x00A1;
  94. public const int WM_NCLBUTTONUP = 0x00A2;
  95. public const int WM_NCLBUTTONDBLCLK = 0x00A3;
  96. public const int WM_NCMOUSEMOVE = 0x00A0;
  97. public const int WM_NCHITTEST = 0x0084;
  98. public const int HTLEFT = 10;
  99. public const int HTRIGHT = 11;
  100. public const int HTTOP = 12;
  101. public const int HTTOPLEFT = 13;
  102. public const int HTTOPRIGHT = 14;
  103. public const int HTBOTTOM = 15;
  104. public const int HTBOTTOMLEFT = 0x10;
  105. public const int HTBOTTOMRIGHT = 17;
  106. public const int HTCAPTION = 2;
  107. public const int HTCLIENT = 1;
  108. public const int WM_FALSE = 0;
  109. public const int WM_TRUE = 1;
  110. #endregion
  111. /// <summary>
  112. /// 执行动画
  113. /// </summary>
  114. /// <param name="whnd">控件句柄</param>
  115. /// <param name="dwtime">动画时间</param>
  116. /// <param name="dwflag">动画组合名称</param>
  117. /// <returns>bool值,动画是否成功</returns>
  118. [DllImport("user32")]
  119. public static extern bool AnimateWindow(IntPtr whnd, int dwtime, int dwflag);
  120. [DllImport("user32")]
  121. public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
  122. [DllImport("gdi32.dll")]
  123. public static extern int CreateRoundRectRgn(int x1, int y1, int x2, int y2, int x3, int y3);
  124. [DllImport("user32.dll")]
  125. public static extern int SetWindowRgn(IntPtr hwnd, int hRgn, Boolean bRedraw);
  126. [DllImport("user32", EntryPoint = "GetWindowLong")]
  127. public static extern uint GetWindowLong(IntPtr hwnd, int nIndex);
  128. [DllImport("user32", EntryPoint = "SetWindowLong")]
  129. public static extern uint SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong);
  130. [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
  131. public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
  132. [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
  133. public static extern IntPtr GetDC(IntPtr hWnd);
  134. [DllImport("gdi32.dll", ExactSpelling = true)]
  135. public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObj);
  136. [DllImport("user32.dll", ExactSpelling = true)]
  137. public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
  138. [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
  139. public static extern int DeleteDC(IntPtr hDC);
  140. [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
  141. public static extern int DeleteObject(IntPtr hObj);
  142. [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
  143. public static extern int UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref Point pptDst, ref Size psize, IntPtr hdcSrc, ref Point pptSrc, Int32 crKey, ref BLENDFUNCTION pblend, Int32 dwFlags);
  144. [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
  145. public static extern IntPtr ExtCreateRegion(IntPtr lpXform, uint nCount, IntPtr rgnData);
  146. [DllImport("user32.dll")]
  147. public static extern bool ReleaseCapture();
  148. [DllImport("user32.dll")]
  149. public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
  150. }
  151. }