wpf 状态栏图标背景闪烁提醒 FlashWindowEx
原文:wpf 状态栏图标背景闪烁提醒 FlashWindowEx
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
namespace XCommon {
public static class WindowExtensions {
#region Window Flashing API Stuff
private const UInt32 FLASHW_STOP = 0; //Stop flashing. The system restores the window to its original state.
private const UInt32 FLASHW_CAPTION = 1; //Flash the window caption.
private const UInt32 FLASHW_TRAY = 2; //Flash the taskbar button.
private const UInt32 FLASHW_ALL = 3; //Flash both the window caption and taskbar button.
private const UInt32 FLASHW_TIMER = 4; //Flash continuously, until the FLASHW_STOP flag is set.
private const UInt32 FLASHW_TIMERNOFG = 12; //Flash continuously until the window comes to the foreground.
[StructLayout(LayoutKind.Sequential)]
private struct FLASHWINFO {
public UInt32 cbSize; //The size of the structure in bytes.
public IntPtr hwnd; //A Handle to the Window to be Flashed. The window can be either opened or minimized.
public UInt32 dwFlags; //The Flash Status.
public UInt32 uCount; // number of times to flash the window
public UInt32 dwTimeout; //The rate at which the Window is to be flashed, in milliseconds. If Zero, the function uses the default cursor blink rate.
}
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool FlashWindowEx(ref FLASHWINFO pwfi);
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
#endregion
public static void FlashWindow(this Window win, UInt32 count = UInt32.MaxValue, UInt32 interval = 100) {
//Don't flash if the window is active
if (win.IsActive) return;
WindowInteropHelper h = new WindowInteropHelper(win);
FLASHWINFO info = new FLASHWINFO {
hwnd = h.Handle,
dwFlags = FLASHW_ALL | FLASHW_TIMER,
uCount = count,
dwTimeout = interval
};
info.cbSize = Convert.ToUInt32(Marshal.SizeOf(info));
FlashWindowEx(ref info);
}
public static void StopFlashingWindow(this Window win) {
WindowInteropHelper h = new WindowInteropHelper(win);
FLASHWINFO info = new FLASHWINFO();
info.hwnd = h.Handle;
info.cbSize = Convert.ToUInt32(Marshal.SizeOf(info));
info.dwFlags = FLASHW_STOP;
info.uCount = UInt32.MaxValue;
info.dwTimeout = 0;
FlashWindowEx(ref info);
}
}
}
使用方法:
开始闪烁:FlashWindow(this Window win, UInt32 count = UInt32.MaxValue, UInt32 interval = 100)
win 主窗体,count 闪动次数微信是4次,interval 闪烁间隔毫秒
例子:WindowExtensions.FlashWindow(this, 5, 500);
停止闪烁:
private void window_OnActivated(object sender, EventArgs e) {
if (this.IsActive) {
if (notificationTimer.Enabled) {
notificationTimer.Enabled = false; // 停止闪烁通知区域图标
notifyIcon.Icon = icons[0];
}
WindowExtensions.StopFlashingWindow(this); // 停止闪烁任务栏
}
}
wpf 状态栏图标背景闪烁提醒 FlashWindowEx的更多相关文章
- WPF 任务栏背景闪烁提醒
原文:WPF 任务栏图标闪烁提醒 public static class FlashWindow { [DllImport("user32.dll")] [return: Ma ...
- Mac状态栏wifi图标一直闪烁重复连接但是网络正常的解决办法
本猫的系统是EI(10.11.6),不知从哪个版本开始(至少是升级到EI之后),状态栏上的wifi图标一直闪烁,这应该是表示正在连接网络.但是网络是正常的! 虽说闪烁的wifi图标不影响使用,但是有强 ...
- iOS 设置状态栏的背景颜色
设置状态栏的背景颜色 - (void)setStatusBarBackgroundColor:(UIColor *)color { UIView *statusBar = [[[UIApplicati ...
- 解决Winform应用程序中窗体背景闪烁的问题
本文转载:https://my.oschina.net/Tsybius2014/blog/659742 我的操作系统是Win7,使用的VS版本是VS2012,文中的代码都是C#代码. 这几天遇到一个问 ...
- listview滚动时背景闪烁,背景黑或白问题解决
android在使用listview时出现滚动时背景闪烁,变成背景黑或白的问题这样处理: 1:在布局文件中listview标签中加入: android:cacheColorHint="#00 ...
- android launcher开发之图标背景以及默认配置
1:然后我自己看了一下桌面图标的载入过程: 桌面第一次载入时是默认读取一个xml配置文件,完毕配置工作.这个配置文件在Launcher文件夹下, 路径是:\Launcher\res\xml\defau ...
- Eclipse自定义启动画面和状态栏图标以及各种小图标的含义
一. 启动画面自定义 第一种情况:纯Eclipse 找到Eclipse安装路径下\eclipse\plugins\org.eclipse.platform_3.7.2.v201202080800,具体 ...
- WPF字体图标——IconFont
原文:WPF字体图标--IconFont 版权声明:本文为[CSDN博主:松一160]原创文章,未经允许不得转载. https://blog.csdn.net/songyi160/article/de ...
- WPF字体图标——FontAwesom
原文:WPF字体图标--FontAwesom 版权声明:本文为[CSDN博主:松一160]原创文章,未经允许不得转载. https://blog.csdn.net/songyi160/article/ ...
随机推荐
- Oracle 11gR2_database在Linux下的安装
Oracle 11gR2_database在Linux下的安装 by:授客 QQ:1033553122 由于篇幅问题,采用链接分享的形式,烦请复制以下网址,黏贴到浏览器中打开,下载 http://pa ...
- 修复cocos2dx的Label,WP8下不能换行的问题
注:2014年12月23日有内存/性能优化更新,内容在下面分割线后 搞了几个小时,这个头疼的问题,我给出代码吧. 找到 libcocos2d/platform/winrt/CCFreeTypeFont ...
- idea 自动换行
如下:
- WebStorm连接Github教程
上学期刚开学的时候看过一次git相关的内容,很久没用过,忘了,两个月前又看了一次还精心做了笔记,也没有具体使用,又忘了,所以,避免又双叒叕忘了,我决定正式把git用起来.刚开始是通过Git Bash来 ...
- 【转】如何将MySQL数据目录更改为CentOS 7上的新位置
本文转载自:http://www.leftso.com/blog/362.html 介绍 数据库随着时间的推移而增长,有时超过了文件系统的空间.当它们与操作系统的其他部分位于同一分区上时,也可能遇到I ...
- woff字体MIME类型配置
<system.webServer> <staticContent> <remove fileExtension=".woff" /> < ...
- Web的攻击技术笔记
HTTP不具备必要的安全功能,就是一个通用的单纯协议机制,比如远程登录时会用到的SSH协议来说,SSH具备协议级别的认证及回话管理等功能,HTTP协议则没有.另外在架设SSH服务方面,任何人都可以轻易 ...
- Debian-Linux配置网卡网络方法
Debian不同于centos系统,网卡配置不是在/etc/sysconfig/network-scrip里面,而是在/etc/network/interfaces里面 1.Debian网络配置 配置 ...
- 05LaTeX学习系列之---TeX的命令行操作
目录 目录 前言 (一)查看版本号 1.查看TeX的版本号 2.查看LaTeX的版本号 3.查看XeLeTeX的版本号 (二)更行版本 (三)用命令行来编译.tex文件 1.用LaTeX编译 2.用X ...
- tkinter学习系列(三)之Label控件
目录 目录 前言 (一)基本用法和可选属性 ==1.基本用法== ==2.可选属性== (二)属性的具体使用 ==1.常用属性== ==2.边距与文本对齐方式== ==案例一== ==案例一的效果== ...