FrmAnchorTips.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. // ***********************************************************************
  2. // Assembly : HZH_Controls
  3. // Created : 08-29-2019
  4. //
  5. // ***********************************************************************
  6. // <copyright file="FrmAnchorTips.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.ComponentModel;
  19. using System.Data;
  20. using System.Drawing;
  21. using System.Drawing.Drawing2D;
  22. using System.Linq;
  23. using System.Runtime.InteropServices;
  24. using System.Text;
  25. using System.Windows.Forms;
  26. namespace HZH_Controls.Forms
  27. {
  28. /// <summary>
  29. /// Class FrmAnchorTips.
  30. /// Implements the <see cref="System.Windows.Forms.Form" />
  31. /// </summary>
  32. /// <seealso cref="System.Windows.Forms.Form" />
  33. public partial class FrmAnchorTips : Form
  34. {
  35. /// <summary>
  36. /// The m string MSG
  37. /// </summary>
  38. private string m_strMsg = string.Empty;
  39. /// <summary>
  40. /// Gets or sets the string MSG.
  41. /// </summary>
  42. /// <value>The string MSG.</value>
  43. public string StrMsg
  44. {
  45. get { return m_strMsg; }
  46. set
  47. {
  48. m_strMsg = value;
  49. if (string.IsNullOrEmpty(value))
  50. return;
  51. ResetForm(value);
  52. }
  53. }
  54. /// <summary>
  55. /// The have handle
  56. /// </summary>
  57. bool haveHandle = false;
  58. /// <summary>
  59. /// The m rect control
  60. /// </summary>
  61. Rectangle m_rectControl;
  62. /// <summary>
  63. /// Gets or sets the rect control.
  64. /// </summary>
  65. /// <value>The rect control.</value>
  66. public Rectangle RectControl
  67. {
  68. get { return m_rectControl; }
  69. set
  70. {
  71. m_rectControl = value;
  72. }
  73. }
  74. /// <summary>
  75. /// The m location
  76. /// </summary>
  77. AnchorTipsLocation m_location;
  78. /// <summary>
  79. /// The m background
  80. /// </summary>
  81. Color? m_background = null;
  82. /// <summary>
  83. /// The m fore color
  84. /// </summary>
  85. Color? m_foreColor = null;
  86. /// <summary>
  87. /// The m font size
  88. /// </summary>
  89. int m_fontSize = 10;
  90. #region 构造函数 English:Constructor
  91. /// <summary>
  92. /// Initializes a new instance of the <see cref="FrmAnchorTips"/> class.
  93. /// </summary>
  94. /// <param name="rectControl">The rect control.</param>
  95. /// <param name="strMsg">The string MSG.</param>
  96. /// <param name="location">The location.</param>
  97. /// <param name="background">The background.</param>
  98. /// <param name="foreColor">Color of the fore.</param>
  99. /// <param name="fontSize">Size of the font.</param>
  100. /// <param name="autoCloseTime">The automatic close time.</param>
  101. private FrmAnchorTips(
  102. Rectangle rectControl,
  103. string strMsg,
  104. AnchorTipsLocation location = AnchorTipsLocation.RIGHT,
  105. Color? background = null,
  106. Color? foreColor = null,
  107. int fontSize = 10,
  108. int autoCloseTime = 5000)
  109. {
  110. InitializeComponent();
  111. m_rectControl = rectControl;
  112. m_location = location;
  113. m_background = background;
  114. m_foreColor = foreColor;
  115. m_fontSize = fontSize;
  116. StrMsg = strMsg;
  117. if (autoCloseTime > 0)
  118. {
  119. Timer t = new Timer();
  120. t.Interval = autoCloseTime;
  121. t.Tick += (a, b) =>
  122. {
  123. this.Close();
  124. };
  125. t.Enabled = true;
  126. }
  127. }
  128. /// <summary>
  129. /// Resets the form.
  130. /// </summary>
  131. /// <param name="strMsg">The string MSG.</param>
  132. private void ResetForm(string strMsg)
  133. {
  134. Graphics g = this.CreateGraphics();
  135. Font _font = new Font("微软雅黑", m_fontSize);
  136. Color _background = m_background == null ? Color.FromArgb(255, 77, 58) : m_background.Value;
  137. Color _foreColor = m_foreColor == null ? Color.White : m_foreColor.Value;
  138. System.Drawing.SizeF sizeText = g.MeasureString(strMsg, _font);
  139. g.Dispose();
  140. var formSize = new Size((int)sizeText.Width + 10, (int)sizeText.Height + 10);
  141. if (formSize.Width < 10)
  142. formSize.Width = 10;
  143. if (formSize.Height < 10)
  144. formSize.Height = 10;
  145. if (m_location == AnchorTipsLocation.LEFT || m_location == AnchorTipsLocation.RIGHT)
  146. {
  147. formSize.Width += 20;
  148. }
  149. else
  150. {
  151. formSize.Height += 20;
  152. }
  153. #region 获取窗体path English:Get the form path
  154. GraphicsPath path = new GraphicsPath();
  155. Rectangle rect;
  156. switch (m_location)
  157. {
  158. case AnchorTipsLocation.TOP:
  159. rect = new Rectangle(1, 1, formSize.Width - 2, formSize.Height - 20 - 1);
  160. this.Location = new Point(m_rectControl.X + (m_rectControl.Width - rect.Width) / 2, m_rectControl.Y - rect.Height - 20);
  161. break;
  162. case AnchorTipsLocation.RIGHT:
  163. rect = new Rectangle(20, 1, formSize.Width - 20 - 1, formSize.Height - 2);
  164. this.Location = new Point(m_rectControl.Right, m_rectControl.Y + (m_rectControl.Height - rect.Height) / 2);
  165. break;
  166. case AnchorTipsLocation.BOTTOM:
  167. rect = new Rectangle(1, 20, formSize.Width - 2, formSize.Height - 20 - 1);
  168. this.Location = new Point(m_rectControl.X + (m_rectControl.Width - rect.Width) / 2, m_rectControl.Bottom);
  169. break;
  170. default:
  171. rect = new Rectangle(1, 1, formSize.Width - 20 - 1, formSize.Height - 2);
  172. this.Location = new Point(m_rectControl.X - rect.Width - 20, m_rectControl.Y + (m_rectControl.Height - rect.Height) / 2);
  173. break;
  174. }
  175. int cornerRadius = 2;
  176. path.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);//左上角
  177. #region 上边
  178. if (m_location == AnchorTipsLocation.BOTTOM)
  179. {
  180. path.AddLine(rect.X + cornerRadius, rect.Y, rect.Left + rect.Width / 2 - 10, rect.Y);//上
  181. path.AddLine(rect.Left + rect.Width / 2 - 10, rect.Y, rect.Left + rect.Width / 2, rect.Y - 19);//上
  182. path.AddLine(rect.Left + rect.Width / 2, rect.Y - 19, rect.Left + rect.Width / 2 + 10, rect.Y);//上
  183. path.AddLine(rect.Left + rect.Width / 2 + 10, rect.Y, rect.Right - cornerRadius * 2, rect.Y);//上
  184. }
  185. else
  186. {
  187. path.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y);//上
  188. }
  189. #endregion
  190. path.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);//右上角
  191. #region 右边
  192. if (m_location == AnchorTipsLocation.LEFT)
  193. {
  194. path.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height / 2 - 10);//右
  195. path.AddLine(rect.Right, rect.Y + rect.Height / 2 - 10, rect.Right + 19, rect.Y + rect.Height / 2);//右
  196. path.AddLine(rect.Right + 19, rect.Y + rect.Height / 2, rect.Right, rect.Y + rect.Height / 2 + 10);//右
  197. path.AddLine(rect.Right, rect.Y + rect.Height / 2 + 10, rect.Right, rect.Y + rect.Height - cornerRadius * 2);//右
  198. }
  199. else
  200. {
  201. path.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2);//右
  202. }
  203. #endregion
  204. path.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);//右下角
  205. #region 下边
  206. if (m_location == AnchorTipsLocation.TOP)
  207. {
  208. path.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.Left + rect.Width / 2 + 10, rect.Bottom);
  209. path.AddLine(rect.Left + rect.Width / 2 + 10, rect.Bottom, rect.Left + rect.Width / 2, rect.Bottom + 19);
  210. path.AddLine(rect.Left + rect.Width / 2, rect.Bottom + 19, rect.Left + rect.Width / 2 - 10, rect.Bottom);
  211. path.AddLine(rect.Left + rect.Width / 2 - 10, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom);
  212. }
  213. else
  214. {
  215. path.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom);
  216. }
  217. #endregion
  218. path.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);//左下角
  219. #region 左边
  220. if (m_location == AnchorTipsLocation.RIGHT)
  221. {
  222. path.AddLine(rect.Left, rect.Y + cornerRadius * 2, rect.Left, rect.Y + rect.Height / 2 - 10);//左
  223. path.AddLine(rect.Left, rect.Y + rect.Height / 2 - 10, rect.Left - 19, rect.Y + rect.Height / 2);//左
  224. path.AddLine(rect.Left - 19, rect.Y + rect.Height / 2, rect.Left, rect.Y + rect.Height / 2 + 10);//左
  225. path.AddLine(rect.Left, rect.Y + rect.Height / 2 + 10, rect.Left, rect.Y + rect.Height - cornerRadius * 2);//左
  226. }
  227. else
  228. {
  229. path.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);//左
  230. }
  231. #endregion
  232. path.CloseFigure();
  233. #endregion
  234. Bitmap bit = new Bitmap(formSize.Width, formSize.Height);
  235. this.Size = formSize;
  236. #region 画图 English:Drawing
  237. Graphics gBit = Graphics.FromImage(bit);
  238. gBit.SetGDIHigh();
  239. gBit.FillPath(new SolidBrush(_background), path);
  240. gBit.DrawString(strMsg, _font, new SolidBrush(_foreColor), rect, new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
  241. gBit.Dispose();
  242. #endregion
  243. SetBits(bit);
  244. }
  245. #endregion
  246. #region 显示一个提示 English:Show a hint
  247. /// <summary>
  248. /// Shows the tips.
  249. /// </summary>
  250. /// <param name="anchorControl">The parent control.</param>
  251. /// <param name="strMsg">The string MSG.</param>
  252. /// <param name="location">The location.</param>
  253. /// <param name="background">The background.</param>
  254. /// <param name="foreColor">Color of the fore.</param>
  255. /// <param name="deviation">The deviation.</param>
  256. /// <param name="fontSize">Size of the font.</param>
  257. /// <param name="autoCloseTime">The automatic close time.</param>
  258. /// <param name="blnTopMost">是否置顶</param>
  259. /// <returns>FrmAnchorTips.</returns>
  260. public static FrmAnchorTips ShowTips(
  261. Control anchorControl,
  262. string strMsg,
  263. AnchorTipsLocation location = AnchorTipsLocation.RIGHT,
  264. Color? background = null,
  265. Color? foreColor = null,
  266. Size? deviation = null,
  267. int fontSize = 10,
  268. int autoCloseTime = 5000,
  269. bool blnTopMost = true)
  270. {
  271. Point p;
  272. if (anchorControl is Form)
  273. {
  274. p = anchorControl.Location;
  275. }
  276. else
  277. {
  278. p = anchorControl.Parent.PointToScreen(anchorControl.Location);
  279. }
  280. if (deviation != null)
  281. {
  282. p = p + deviation.Value;
  283. }
  284. return ShowTips(new Rectangle(p, anchorControl.Size), strMsg, location, background, foreColor, fontSize, autoCloseTime, anchorControl.Parent, blnTopMost);
  285. }
  286. #endregion
  287. #region 显示一个提示 English:Show a hint
  288. /// <summary>
  289. /// Shows the tips.
  290. /// </summary>
  291. /// <param name="rectControl">The rect control.</param>
  292. /// <param name="strMsg">The string MSG.</param>
  293. /// <param name="location">The location.</param>
  294. /// <param name="background">The background.</param>
  295. /// <param name="foreColor">Color of the fore.</param>
  296. /// <param name="fontSize">Size of the font.</param>
  297. /// <param name="autoCloseTime">The automatic close time.</param>
  298. /// <param name="parentForm">父窗体</param>
  299. /// <param name="blnTopMost">是否置顶</param>
  300. /// <returns>FrmAnchorTips.</returns>
  301. public static FrmAnchorTips ShowTips(
  302. Rectangle rectControl,
  303. string strMsg,
  304. AnchorTipsLocation location = AnchorTipsLocation.RIGHT,
  305. Color? background = null,
  306. Color? foreColor = null,
  307. int fontSize = 10,
  308. int autoCloseTime = 5000,
  309. Control parentControl = null,
  310. bool blnTopMost = true)
  311. {
  312. FrmAnchorTips frm = new FrmAnchorTips(rectControl, strMsg, location, background, foreColor, fontSize, autoCloseTime);
  313. frm.TopMost = blnTopMost;
  314. frm.Show(parentControl);
  315. //if (parentControl != null)
  316. //{
  317. // parentControl.VisibleChanged += (a, b) =>
  318. // {
  319. // try
  320. // {
  321. // Control c = a as Control;
  322. // if (CheckControlClose(c))
  323. // {
  324. // frm.Close();
  325. // }
  326. // }
  327. // catch (Exception ex)
  328. // {
  329. // }
  330. // };
  331. //}
  332. return frm;
  333. }
  334. private static bool CheckControlClose(Control c)
  335. {
  336. if (c.IsDisposed || !c.Visible)
  337. return true;
  338. else if (c.Parent != null)
  339. return CheckControlClose(c.Parent);
  340. else
  341. {
  342. if (c is Form)
  343. return false;
  344. else
  345. return true;
  346. }
  347. }
  348. #endregion
  349. #region Override
  350. /// <summary>
  351. /// 引发 <see cref="E:System.Windows.Forms.Form.Closing" /> 事件。
  352. /// </summary>
  353. /// <param name="e">一个包含事件数据的 <see cref="T:System.ComponentModel.CancelEventArgs" />。</param>
  354. protected override void OnClosing(CancelEventArgs e)
  355. {
  356. e.Cancel = true;
  357. base.OnClosing(e);
  358. haveHandle = false;
  359. this.Dispose();
  360. }
  361. /// <summary>
  362. /// Handles the <see cref="E:HandleCreated" /> event.
  363. /// </summary>
  364. /// <param name="e">包含事件数据的 <see cref="T:System.EventArgs" />。</param>
  365. protected override void OnHandleCreated(EventArgs e)
  366. {
  367. InitializeStyles();
  368. base.OnHandleCreated(e);
  369. haveHandle = true;
  370. }
  371. /// <summary>
  372. /// Gets the create parameters.
  373. /// </summary>
  374. /// <value>The create parameters.</value>
  375. protected override CreateParams CreateParams
  376. {
  377. get
  378. {
  379. CreateParams cParms = base.CreateParams;
  380. cParms.ExStyle |= 0x00080000; // WS_EX_LAYERED
  381. return cParms;
  382. }
  383. }
  384. #endregion
  385. /// <summary>
  386. /// Initializes the styles.
  387. /// </summary>
  388. private void InitializeStyles()
  389. {
  390. SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  391. SetStyle(ControlStyles.UserPaint, true);
  392. UpdateStyles();
  393. }
  394. #region 根据图片显示窗体 English:Display Forms Based on Pictures
  395. /// <summary>
  396. /// 功能描述:根据图片显示窗体 English:Display Forms Based on Pictures
  397. /// 作  者:HZH
  398. /// 创建日期:2019-08-29 15:31:16
  399. /// 任务编号:
  400. /// </summary>
  401. /// <param name="bitmap">bitmap</param>
  402. /// <exception cref="System.ApplicationException">The picture must be 32bit picture with alpha channel.</exception>
  403. /// <exception cref="ApplicationException">The picture must be 32bit picture with alpha channel.</exception>
  404. private void SetBits(Bitmap bitmap)
  405. {
  406. if (!haveHandle) return;
  407. if (!Bitmap.IsCanonicalPixelFormat(bitmap.PixelFormat) || !Bitmap.IsAlphaPixelFormat(bitmap.PixelFormat))
  408. throw new ApplicationException("The picture must be 32bit picture with alpha channel.");
  409. IntPtr oldBits = IntPtr.Zero;
  410. IntPtr screenDC = Win32.GetDC(IntPtr.Zero);
  411. IntPtr hBitmap = IntPtr.Zero;
  412. IntPtr memDc = Win32.CreateCompatibleDC(screenDC);
  413. try
  414. {
  415. Win32.Point topLoc = new Win32.Point(Left, Top);
  416. Win32.Size bitMapSize = new Win32.Size(bitmap.Width, bitmap.Height);
  417. Win32.BLENDFUNCTION blendFunc = new Win32.BLENDFUNCTION();
  418. Win32.Point srcLoc = new Win32.Point(0, 0);
  419. hBitmap = bitmap.GetHbitmap(Color.FromArgb(0));
  420. oldBits = Win32.SelectObject(memDc, hBitmap);
  421. blendFunc.BlendOp = Win32.AC_SRC_OVER;
  422. blendFunc.SourceConstantAlpha = 255;
  423. blendFunc.AlphaFormat = Win32.AC_SRC_ALPHA;
  424. blendFunc.BlendFlags = 0;
  425. Win32.UpdateLayeredWindow(Handle, screenDC, ref topLoc, ref bitMapSize, memDc, ref srcLoc, 0, ref blendFunc, Win32.ULW_ALPHA);
  426. }
  427. finally
  428. {
  429. if (hBitmap != IntPtr.Zero)
  430. {
  431. Win32.SelectObject(memDc, oldBits);
  432. Win32.DeleteObject(hBitmap);
  433. }
  434. Win32.ReleaseDC(IntPtr.Zero, screenDC);
  435. Win32.DeleteDC(memDc);
  436. }
  437. }
  438. #endregion
  439. #region 无焦点窗体处理
  440. /// <summary>
  441. /// Sets the active window.
  442. /// </summary>
  443. /// <param name="handle">The handle.</param>
  444. /// <returns>IntPtr.</returns>
  445. [System.Runtime.InteropServices.DllImport("user32.dll")]
  446. private extern static IntPtr SetActiveWindow(IntPtr handle);
  447. /// <summary>
  448. /// The wm activate
  449. /// </summary>
  450. private const int WM_ACTIVATE = 0x006;
  451. /// <summary>
  452. /// The wm activateapp
  453. /// </summary>
  454. private const int WM_ACTIVATEAPP = 0x01C;
  455. /// <summary>
  456. /// The wm ncactivate
  457. /// </summary>
  458. private const int WM_NCACTIVATE = 0x086;
  459. /// <summary>
  460. /// The wa inactive
  461. /// </summary>
  462. private const int WA_INACTIVE = 0;
  463. /// <summary>
  464. /// The wm mouseactivate
  465. /// </summary>
  466. private const int WM_MOUSEACTIVATE = 0x21;
  467. /// <summary>
  468. /// The ma noactivate
  469. /// </summary>
  470. private const int MA_NOACTIVATE = 3;
  471. /// <summary>
  472. /// WNDs the proc.
  473. /// </summary>
  474. /// <param name="m">要处理的 Windows <see cref="T:System.Windows.Forms.Message" />。</param>
  475. protected override void WndProc(ref Message m)
  476. {
  477. if (m.Msg == WM_MOUSEACTIVATE)
  478. {
  479. m.Result = new IntPtr(MA_NOACTIVATE);
  480. return;
  481. }
  482. else if (m.Msg == WM_NCACTIVATE)
  483. {
  484. if (((int)m.WParam & 0xFFFF) != WA_INACTIVE)
  485. {
  486. if (m.LParam != IntPtr.Zero)
  487. {
  488. SetActiveWindow(m.LParam);
  489. }
  490. else
  491. {
  492. SetActiveWindow(IntPtr.Zero);
  493. }
  494. }
  495. }
  496. base.WndProc(ref m);
  497. }
  498. #endregion
  499. }
  500. /// <summary>
  501. /// Enum AnchorTipsLocation
  502. /// </summary>
  503. public enum AnchorTipsLocation
  504. {
  505. /// <summary>
  506. /// The left
  507. /// </summary>
  508. LEFT,
  509. /// <summary>
  510. /// The top
  511. /// </summary>
  512. TOP,
  513. /// <summary>
  514. /// The right
  515. /// </summary>
  516. RIGHT,
  517. /// <summary>
  518. /// The bottom
  519. /// </summary>
  520. BOTTOM
  521. }
  522. /// <summary>
  523. /// Class Win32.
  524. /// </summary>
  525. class Win32
  526. {
  527. /// <summary>
  528. /// Struct Size
  529. /// </summary>
  530. [StructLayout(LayoutKind.Sequential)]
  531. public struct Size
  532. {
  533. /// <summary>
  534. /// The cx
  535. /// </summary>
  536. public Int32 cx;
  537. /// <summary>
  538. /// The cy
  539. /// </summary>
  540. public Int32 cy;
  541. /// <summary>
  542. /// Initializes a new instance of the <see cref="Size" /> struct.
  543. /// </summary>
  544. /// <param name="x">The x.</param>
  545. /// <param name="y">The y.</param>
  546. public Size(Int32 x, Int32 y)
  547. {
  548. cx = x;
  549. cy = y;
  550. }
  551. }
  552. /// <summary>
  553. /// Struct BLENDFUNCTION
  554. /// </summary>
  555. [StructLayout(LayoutKind.Sequential, Pack = 1)]
  556. public struct BLENDFUNCTION
  557. {
  558. /// <summary>
  559. /// The blend op
  560. /// </summary>
  561. public byte BlendOp;
  562. /// <summary>
  563. /// The blend flags
  564. /// </summary>
  565. public byte BlendFlags;
  566. /// <summary>
  567. /// The source constant alpha
  568. /// </summary>
  569. public byte SourceConstantAlpha;
  570. /// <summary>
  571. /// The alpha format
  572. /// </summary>
  573. public byte AlphaFormat;
  574. }
  575. /// <summary>
  576. /// Struct Point
  577. /// </summary>
  578. [StructLayout(LayoutKind.Sequential)]
  579. public struct Point
  580. {
  581. /// <summary>
  582. /// The x
  583. /// </summary>
  584. public Int32 x;
  585. /// <summary>
  586. /// The y
  587. /// </summary>
  588. public Int32 y;
  589. /// <summary>
  590. /// Initializes a new instance of the <see cref="Point" /> struct.
  591. /// </summary>
  592. /// <param name="x">The x.</param>
  593. /// <param name="y">The y.</param>
  594. public Point(Int32 x, Int32 y)
  595. {
  596. this.x = x;
  597. this.y = y;
  598. }
  599. }
  600. /// <summary>
  601. /// The ac source over
  602. /// </summary>
  603. public const byte AC_SRC_OVER = 0;
  604. /// <summary>
  605. /// The ulw alpha
  606. /// </summary>
  607. public const Int32 ULW_ALPHA = 2;
  608. /// <summary>
  609. /// The ac source alpha
  610. /// </summary>
  611. public const byte AC_SRC_ALPHA = 1;
  612. /// <summary>
  613. /// Creates the compatible dc.
  614. /// </summary>
  615. /// <param name="hDC">The h dc.</param>
  616. /// <returns>IntPtr.</returns>
  617. [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
  618. public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
  619. /// <summary>
  620. /// Gets the dc.
  621. /// </summary>
  622. /// <param name="hWnd">The h WND.</param>
  623. /// <returns>IntPtr.</returns>
  624. [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
  625. public static extern IntPtr GetDC(IntPtr hWnd);
  626. /// <summary>
  627. /// Selects the object.
  628. /// </summary>
  629. /// <param name="hDC">The h dc.</param>
  630. /// <param name="hObj">The h object.</param>
  631. /// <returns>IntPtr.</returns>
  632. [DllImport("gdi32.dll", ExactSpelling = true)]
  633. public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObj);
  634. /// <summary>
  635. /// Releases the dc.
  636. /// </summary>
  637. /// <param name="hWnd">The h WND.</param>
  638. /// <param name="hDC">The h dc.</param>
  639. /// <returns>System.Int32.</returns>
  640. [DllImport("user32.dll", ExactSpelling = true)]
  641. public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
  642. /// <summary>
  643. /// Deletes the dc.
  644. /// </summary>
  645. /// <param name="hDC">The h dc.</param>
  646. /// <returns>System.Int32.</returns>
  647. [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
  648. public static extern int DeleteDC(IntPtr hDC);
  649. /// <summary>
  650. /// Deletes the object.
  651. /// </summary>
  652. /// <param name="hObj">The h object.</param>
  653. /// <returns>System.Int32.</returns>
  654. [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
  655. public static extern int DeleteObject(IntPtr hObj);
  656. /// <summary>
  657. /// Updates the layered window.
  658. /// </summary>
  659. /// <param name="hwnd">The HWND.</param>
  660. /// <param name="hdcDst">The HDC DST.</param>
  661. /// <param name="pptDst">The PPT DST.</param>
  662. /// <param name="psize">The psize.</param>
  663. /// <param name="hdcSrc">The HDC source.</param>
  664. /// <param name="pptSrc">The PPT source.</param>
  665. /// <param name="crKey">The cr key.</param>
  666. /// <param name="pblend">The pblend.</param>
  667. /// <param name="dwFlags">The dw flags.</param>
  668. /// <returns>System.Int32.</returns>
  669. [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
  670. 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);
  671. /// <summary>
  672. /// Exts the create region.
  673. /// </summary>
  674. /// <param name="lpXform">The lp xform.</param>
  675. /// <param name="nCount">The n count.</param>
  676. /// <param name="rgnData">The RGN data.</param>
  677. /// <returns>IntPtr.</returns>
  678. [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
  679. public static extern IntPtr ExtCreateRegion(IntPtr lpXform, uint nCount, IntPtr rgnData);
  680. }
  681. }