FormStyleAPI.cs 6.4 KB

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