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/ ...
随机推荐
- 云卡门禁安卓SDK_BLEDOOR_SDK_ANDROID_2016_12_15
package com.bosk.bledoor.sdk; //sdk包的开门服务类,AndroidManifest.xml 必须注册 //<service //android:name=&qu ...
- Ubuntu16.04升级 Ubuntu18.04
1.更新资源 $ sudo apt-get update $ sudo apt-get upgrade $ sudo apt dist-upgrade 2.安装update-manager-core ...
- SVN——Couldn't perform atomic initialization
前言 今天早上刚刚打开我的电脑,就被李总他们告知不能正确用SVN从服务器上下载代码了,然后看问题吧.问题其实也是本文的标题,并不难解决,写下来留个记录,顺便也算是一种分享.问题截图如下: 造 ...
- Android 电池系列
android 电池(一):锂电池基本原理篇 android 电池(二):android关机充电流程.充电画面显示 android 电池(三):android电池系统 android电池(四):电池 ...
- docker端口映射启动报错Error response from daemon: driver failed programming external connectivity on endpoint jms_guacamole
问题描述:今天跳板机的一个guacamole用docker重新启动报错了 [root@localhost opt]# docker start d82e9c342a Error response / ...
- 12个HTML和CSS必须知道的重点难点问题
这12个问题,基本上就是HTML和CSS基础中的重点个难点了,也是必须要弄清楚的基本问题,其中定位的绝对定位和相对定位到底相对什么定位?这个还是容易被忽视的,浮动也是一个大坑,有很多细节.这12个知识 ...
- 个人博客作业Week3(微软必应词典客户端的案例分析)
软件缺陷常常又被叫做Bug,即为计算机软件或程序中存在的某种破坏正常运行能力的问题.错误,或者隐藏的功能缺陷.缺陷的存在会导致软件产品在某种程度上不能满足用户的需要.IEEE729-1983对缺陷有一 ...
- Java设计模式之九 ----- 解释器模式和迭代器模式
前言 在上一篇中我们学习了行为型模式的责任链模式(Chain of Responsibility Pattern)和命令模式(Command Pattern).本篇则来学习下行为型模式的两个模式, 解 ...
- postMessage 实现跨源通信 iframe 跨域获取url
用postMessage实现跨源通信的方法实例 如:在www.bbb.com/index.html页面获取www.aaa.com/index.html的数据,以iframe的形式 www.aaa.co ...
- IE8以下兼容
<!--[if lt IE 9]><script type="text/javascript">alert('IE版本太低,请升级后使用');</sc ...