WPF 任务栏图标闪烁提醒

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

FlashWindow

启动:FlashWindow.Start(Window w);

停止:FlashWindow.Stop(Window w);

.NET技术交流群 199281001 .欢迎加入。

WPF 任务栏图标闪烁提醒

时间: 2024-10-15 15:55:18

WPF 任务栏图标闪烁提醒的相关文章

WPF 系统托盘 图标闪烁

WPF消息通知 系统托盘,图标闪烁 1 using System.Windows.Forms; 2 3 using System.Windows.Threading; 4 5 public partial class Window : Window 6 { 7 private NotifyIcon notifyIcon; 8 DispatcherTimer icoTimer = new DispatcherTimer(); 9 string icoUrl = @"../../Red.ico&qu

电脑任务栏闪烁以及任务栏图标闪烁解决办法

前言:近来笔者发现电脑不时的电脑桌面和菜单栏会不停的闪烁,只能通过Ctrl + shift + ESC打开任务管理器来重启资源管理器,但是发现重启之后的一会儿好了,但是过一会儿又闪烁,后来琢磨好久,才发现是有软件在更改默认软件,造成资源管理器不断重启,所以桌面图标才不断闪烁,恢复系统默认软件后就好了,下面将方法分享给大家 一,按win键就是键盘左下角Ctrl键右边的一个,然后选择设置按钮,如下如所示 二.打开如下界面,我们选择应用这个选项,如下图所示 三.选择之后选择默认应用 四.选择之后在右边

C#:实现托盘(任务栏图标与托盘图标互斥)

实现托盘(任务栏图标与托盘图标互斥),并且在点击任务栏图标时实现的最小化与点击最小化按钮分离. 具体如下: 1.向窗体上添加如下控件:MenuStrip menuStrip1, NotifyIcon ni_frmMain,Timer timer1, ContentMenuStrip cms_notify.其中notify中包含显示.退出等. 2.实现的代码: //字段: //当前子Form private CurrentForm childForm = null; //上次窗体的状态 priva

windows 任务栏图标宽度固定

这个需要修改注册表. win+r regedit ->enter 找到以下项 HKEY_CURRENT_USER-Control Panel-Desktop-WindowsMetrics 新建字符键值.. MinWidth 54 MaxWidth 55 注销重新登录.. 效果如图. windows 任务栏图标宽度固定,码迷,mamicode.com

C#实现无标题栏窗体点击任务栏图标正常最小化或还原的解决方法

对于无标题栏窗体,也就是FormBorderStyle等于System.Windows.Forms.FormBorderStyle.None的窗体,点击任务栏图标的时候,是不能象标准窗体那样最小化或还原的.把下面的代码加到你的Form实现类中,即可实现点击任务栏图标正常最小化或还原窗体. [c-sharp] view plain copy protected override CreateParams CreateParams { get { const int WS_MINIMIZEBOX =

Atitit.ALT+TAB没反应车and 点击任务栏程序闪烁可是不能切换

Atitit.ALT+TAB没反应车and 点击任务栏程序闪烁可是不能切换 1. 可能你的Alt+Tab键被别人禁用了,试下以下的方法: 1 2. 为什么要禁用Alt+Tab 1 3. ALT+TAB的历史作用 2 4. 解决方式::AltTabTuner1.0.1绿色版(系统设置软件 2 5. 參考 3 1. 可能你的Alt+Tab键被别人禁用了,试下以下的方法: 開始-执行-输入regedit,找到HKEY_CURRENT_USER\Control Panel\Desktop,在右边窗体,双

Atitit.ALT+TAB没反应车and 点击任务栏程序闪烁但是不能切换

Atitit.ALT+TAB没反应车and 点击任务栏程序闪烁但是不能切换 1. 可能你的Alt+Tab键被别人禁用了,试下下面的方法: 1 2. 为什么要禁用Alt+Tab 1 3. ALT+TAB的历史作用 2 4. 解决方案::AltTabTuner1.0.1绿色版(系统设置软件 2 5. 参考 3 1. 可能你的Alt+Tab键被别人禁用了,试下下面的方法: 开始-运行-输入regedit,找到HKEY_CURRENT_USER\Control Panel\Desktop,在右边窗口,双

win7中如何隐藏pcanywhere任务栏图标

pcanywhere是一款远程协助软件,在大型企业网络中得到广泛应用,但有些用户看到任务栏的pcanywhere等待图标,,就会右击此图标"取消主机"造成网络管理员远程连接不到主机,所以如果可以把pcanywhere任务栏图标隐藏掉了,那么用户就不能在图标上点"取消主机"造成连接不到主机的情况了.在网上查找的都是针对XP系统的修改注册表的步骤,后来终于发现原来win7-64位中安装了32位的pcanywhere在注册中的修改的位置: 原xp编辑注册表(regedit

Win10如何隐藏Windows Defender任务栏图标

Windows 10 至发布以来就内置集成了 Windows Defender 安全防护应用,但有许多用户平常压根儿就没注意到它的存在.微软为了使安全防护功能更加明显,Windows 10 周年更新中将 Windows Defender 图标列到了任务栏通知区域,以方便用户使用. 禁用任务栏图标并不会影响到 Windows Defender 的正常工作,它仍会在后台对系统进行安全防护,你可以正常通过「设置」-「更新和安全」-「Windows Defender」或在「开始」菜单中搜索 Window