当前位置:   article > 正文

winform中实现任务栏闪烁_怎样编程判断任务栏闪动的方法呢

怎样编程判断任务栏闪动的方法呢
Demo下载
  1. //======================================================================
  2. //
  3. // 作者:涂剑凯(tujiankai@360buy.com)
  4. // 描述:
  5. // 创建时间:2012-10-23 17:38:43
  6. // 修改时间:2012-10-23 17:38:43
  7. // 修改说明:
  8. // .NET版本:3.5
  9. //
  10. //======================================================================
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Text;
  14. using System.Runtime.InteropServices;
  15. namespace WindowsFormsApplication9
  16. {
  17. public static class FlashWindow
  18. {
  19. [DllImport("user32.dll")]
  20. [return: MarshalAs(UnmanagedType.Bool)]
  21. private static extern bool FlashWindowEx(ref FLASHWINFO pwfi);
  22. [StructLayout(LayoutKind.Sequential)]
  23. private struct FLASHWINFO
  24. {
  25. /// <summary>
  26. /// The size of the structure in bytes.
  27. /// </summary>
  28. public uint cbSize;
  29. /// <summary>
  30. /// A Handle to the Window to be Flashed. The window can be either opened or minimized.
  31. /// </summary>
  32. public IntPtr hwnd;
  33. /// <summary>
  34. /// The Flash Status.
  35. /// </summary>
  36. public uint dwFlags;
  37. /// <summary>
  38. /// The number of times to Flash the window.
  39. /// </summary>
  40. public uint uCount;
  41. /// <summary>
  42. /// The rate at which the Window is to be flashed, in milliseconds. If Zero, the function uses the default cursor blink rate.
  43. /// </summary>
  44. public uint dwTimeout;
  45. }
  46. /// <summary>
  47. /// Stop flashing. The system restores the window to its original stae.
  48. /// </summary>
  49. public const uint FLASHW_STOP = 0;
  50. /// <summary>
  51. /// Flash the window caption.
  52. /// </summary>
  53. public const uint FLASHW_CAPTION = 1;
  54. /// <summary>
  55. /// Flash the taskbar button.
  56. /// </summary>
  57. public const uint FLASHW_TRAY = 2;
  58. /// <summary>
  59. /// Flash both the window caption and taskbar button.
  60. /// This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
  61. /// </summary>
  62. public const uint FLASHW_ALL = 3;
  63. /// <summary>
  64. /// Flash continuously, until the FLASHW_STOP flag is set.
  65. /// </summary>
  66. public const uint FLASHW_TIMER = 4;
  67. /// <summary>
  68. /// Flash continuously until the window comes to the foreground.
  69. /// </summary>
  70. public const uint FLASHW_TIMERNOFG = 12;
  71. /// <summary>
  72. /// Flash the spacified Window (Form) until it recieves focus.
  73. /// </summary>
  74. /// <param name="form">The Form (Window) to Flash.</param>
  75. /// <returns></returns>
  76. public static bool Flash(System.Windows.Forms.Form form)
  77. {
  78. // Make sure we're running under Windows 2000 or later
  79. if (Win2000OrLater)
  80. {
  81. FLASHWINFO fi = Create_FLASHWINFO(form.Handle, FLASHW_ALL | FLASHW_TIMERNOFG, uint.MaxValue, 0);
  82. return FlashWindowEx(ref fi);
  83. }
  84. return false;
  85. }
  86. private static FLASHWINFO Create_FLASHWINFO(IntPtr handle, uint flags, uint count, uint timeout)
  87. {
  88. FLASHWINFO fi = new FLASHWINFO();
  89. fi.cbSize = Convert.ToUInt32(Marshal.SizeOf(fi));
  90. fi.hwnd = handle;
  91. fi.dwFlags = flags;
  92. fi.uCount = count;
  93. fi.dwTimeout = timeout;
  94. return fi;
  95. }
  96. /// <summary>
  97. /// Flash the specified Window (form) for the specified number of times
  98. /// </summary>
  99. /// <param name="form">The Form (Window) to Flash.</param>
  100. /// <param name="count">The number of times to Flash.</param>
  101. /// <returns></returns>
  102. public static bool Flash(System.Windows.Forms.Form form, uint count)
  103. {
  104. if (Win2000OrLater)
  105. {
  106. FLASHWINFO fi = Create_FLASHWINFO(form.Handle, FLASHW_ALL, count, 0);
  107. return FlashWindowEx(ref fi);
  108. }
  109. return false;
  110. }
  111. /// <summary>
  112. /// Start Flashing the specified Window (form)
  113. /// </summary>
  114. /// <param name="form">The Form (Window) to Flash.</param>
  115. /// <returns></returns>
  116. public static bool Start(System.Windows.Forms.Form form)
  117. {
  118. if (Win2000OrLater)
  119. {
  120. FLASHWINFO fi = Create_FLASHWINFO(form.Handle, FLASHW_ALL, uint.MaxValue, 0);
  121. return FlashWindowEx(ref fi);
  122. }
  123. return false;
  124. }
  125. /// <summary>
  126. /// Stop Flashing the specified Window (form)
  127. /// </summary>
  128. /// <param name="form"></param>
  129. /// <returns></returns>
  130. public static bool Stop(System.Windows.Forms.Form form)
  131. {
  132. if (Win2000OrLater)
  133. {
  134. FLASHWINFO fi = Create_FLASHWINFO(form.Handle, FLASHW_STOP, uint.MaxValue, 0);
  135. return FlashWindowEx(ref fi);
  136. }
  137. return false;
  138. }
  139. /// <summary>
  140. /// A boolean value indicating whether the application is running on Windows 2000 or later.
  141. /// </summary>
  142. private static bool Win2000OrLater
  143. {
  144. get { return System.Environment.OSVersion.Version.Major >= 5; }
  145. }
  146. }
  147. }


 

 

//实现闪烁和变色

  1. public partial class FlashWin : Form
  2. {
  3. public struct FLASHWINFO
  4. {
  5. public UInt32 cbSize;
  6. public IntPtr hwnd;
  7. public UInt32 dwFlags;
  8. public UInt32 uCount;
  9. public UInt32 dwTimeout;
  10. }
  11. public FlashWin()
  12. {
  13. InitializeComponent();
  14. }
  15. public const UInt32 FLASHW_STOP = 0;
  16. public const UInt32 FLASHW_CAPTION = 1;
  17. public const UInt32 FLASHW_TRAY = 2;
  18. public const UInt32 FLASHW_ALL = 3;
  19. public const UInt32 FLASHW_TIMER = 4;
  20. public const UInt32 FLASHW_TIMERNOFG = 12;
  21. [DllImport("user32.dll")]
  22. static extern bool FlashWindowEx(ref FLASHWINFO pwfi);
  23. [DllImport("user32.dll")]
  24. static extern bool FlashWindow(IntPtr handle, bool invert);
  25. private void button1_Click(object sender, EventArgs e)
  26. {
  27. this.WindowState = FormWindowState.Minimized;
  28. FLASHWINFO fInfo = new FLASHWINFO();
  29. fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
  30. fInfo.hwnd = this.Handle;
  31. fInfo.dwFlags = FLASHW_TRAY | FLASHW_TIMERNOFG;
  32. fInfo.uCount = UInt32.MaxValue;
  33. fInfo.dwTimeout = 0;
  34. FlashWindowEx(ref fInfo);
  35. }
  36. private void button2_Click(object sender, EventArgs e)
  37. {
  38. this.WindowState = FormWindowState.Minimized;
  39. FlashWindow(this.Handle,true);
  40. }
  41. }


 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/771245
推荐阅读
相关标签
  

闽ICP备14008679号