winform中实现任务栏闪烁
发布时间:2020-12-15 18:26:53 所属栏目:百科 来源:网络整理
导读:Demo下载 //======================================================================//// 作者:涂剑凯(tujiankai@360buy.com)// 描述: // 创建时间:2012-10-23 17:38:43// 修改时间:2012-10-23 17:38:43// 修改说明:// .NET版本:3.5// //===========
Demo下载 //====================================================================== // // 作者:涂剑凯(tujiankai@360buy.com) // 描述: // 创建时间:2012-10-23 17:38:43 // 修改时间:2012-10-23 17:38:43 // 修改说明: // .NET版本:3.5 // //====================================================================== using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace WindowsFormsApplication9 { public static class FlashWindow { [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool FlashWindowEx(ref FLASHWINFO pwfi); [StructLayout(LayoutKind.Sequential)] private struct FLASHWINFO { /// <summary> /// The size of the structure in bytes. /// </summary> public uint cbSize; /// <summary> /// A Handle to the Window to be Flashed. The window can be either opened or minimized. /// </summary> public IntPtr hwnd; /// <summary> /// The Flash Status. /// </summary> public uint dwFlags; /// <summary> /// The number of times to Flash the window. /// </summary> public uint uCount; /// <summary> /// The rate at which the Window is to be flashed,in milliseconds. If Zero,the function uses the default cursor blink rate. /// </summary> public uint dwTimeout; } /// <summary> /// Stop flashing. The system restores the window to its original stae. /// </summary> public const uint FLASHW_STOP = 0; /// <summary> /// Flash the window caption. /// </summary> public const uint FLASHW_CAPTION = 1; /// <summary> /// Flash the taskbar button. /// </summary> public const uint FLASHW_TRAY = 2; /// <summary> /// Flash both the window caption and taskbar button. /// This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags. /// </summary> public const uint FLASHW_ALL = 3; /// <summary> /// Flash continuously,until the FLASHW_STOP flag is set. /// </summary> public const uint FLASHW_TIMER = 4; /// <summary> /// Flash continuously until the window comes to the foreground. /// </summary> public const uint FLASHW_TIMERNOFG = 12; /// <summary> /// Flash the spacified Window (Form) until it recieves focus. /// </summary> /// <param name="form">The Form (Window) to Flash.</param> /// <returns></returns> public static bool Flash(System.Windows.Forms.Form form) { // Make sure we're running under Windows 2000 or later if (Win2000OrLater) { FLASHWINFO fi = Create_FLASHWINFO(form.Handle,FLASHW_ALL | FLASHW_TIMERNOFG,uint.MaxValue,0); return FlashWindowEx(ref fi); } return false; } private static FLASHWINFO Create_FLASHWINFO(IntPtr handle,uint flags,uint count,uint timeout) { FLASHWINFO fi = new FLASHWINFO(); fi.cbSize = Convert.ToUInt32(Marshal.SizeOf(fi)); fi.hwnd = handle; fi.dwFlags = flags; fi.uCount = count; fi.dwTimeout = timeout; return fi; } /// <summary> /// Flash the specified Window (form) for the specified number of times /// </summary> /// <param name="form">The Form (Window) to Flash.</param> /// <param name="count">The number of times to Flash.</param> /// <returns></returns> public static bool Flash(System.Windows.Forms.Form form,uint count) { if (Win2000OrLater) { FLASHWINFO fi = Create_FLASHWINFO(form.Handle,FLASHW_ALL,count,0); return FlashWindowEx(ref fi); } return false; } /// <summary> /// Start Flashing the specified Window (form) /// </summary> /// <param name="form">The Form (Window) to Flash.</param> /// <returns></returns> public static bool Start(System.Windows.Forms.Form form) { if (Win2000OrLater) { FLASHWINFO fi = Create_FLASHWINFO(form.Handle,0); return FlashWindowEx(ref fi); } return false; } /// <summary> /// Stop Flashing the specified Window (form) /// </summary> /// <param name="form"></param> /// <returns></returns> public static bool Stop(System.Windows.Forms.Form form) { if (Win2000OrLater) { FLASHWINFO fi = Create_FLASHWINFO(form.Handle,FLASHW_STOP,0); return FlashWindowEx(ref fi); } return false; } /// <summary> /// A boolean value indicating whether the application is running on Windows 2000 or later. /// </summary> private static bool Win2000OrLater { get { return System.Environment.OSVersion.Version.Major >= 5; } } } }
? //实现闪烁和变色 public partial class FlashWin : Form { public struct FLASHWINFO { public UInt32 cbSize; public IntPtr hwnd; public UInt32 dwFlags; public UInt32 uCount; public UInt32 dwTimeout; } public FlashWin() { InitializeComponent(); } public const UInt32 FLASHW_STOP = 0; public const UInt32 FLASHW_CAPTION = 1; public const UInt32 FLASHW_TRAY = 2; public const UInt32 FLASHW_ALL = 3; public const UInt32 FLASHW_TIMER = 4; public const UInt32 FLASHW_TIMERNOFG = 12; [DllImport("user32.dll")] static extern bool FlashWindowEx(ref FLASHWINFO pwfi); [DllImport("user32.dll")] static extern bool FlashWindow(IntPtr handle,bool invert); private void button1_Click(object sender,EventArgs e) { this.WindowState = FormWindowState.Minimized; FLASHWINFO fInfo = new FLASHWINFO(); fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo)); fInfo.hwnd = this.Handle; fInfo.dwFlags = FLASHW_TRAY | FLASHW_TIMERNOFG; fInfo.uCount = UInt32.MaxValue; fInfo.dwTimeout = 0; FlashWindowEx(ref fInfo); } private void button2_Click(object sender,EventArgs e) { this.WindowState = FormWindowState.Minimized; FlashWindow(this.Handle,true); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |