原文: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的更多相关文章

  1. WPF 任务栏背景闪烁提醒

    原文:WPF 任务栏图标闪烁提醒   public static class FlashWindow { [DllImport("user32.dll")] [return: Ma ...

  2. Mac状态栏wifi图标一直闪烁重复连接但是网络正常的解决办法

    本猫的系统是EI(10.11.6),不知从哪个版本开始(至少是升级到EI之后),状态栏上的wifi图标一直闪烁,这应该是表示正在连接网络.但是网络是正常的! 虽说闪烁的wifi图标不影响使用,但是有强 ...

  3. iOS 设置状态栏的背景颜色

    设置状态栏的背景颜色 - (void)setStatusBarBackgroundColor:(UIColor *)color { UIView *statusBar = [[[UIApplicati ...

  4. 解决Winform应用程序中窗体背景闪烁的问题

    本文转载:https://my.oschina.net/Tsybius2014/blog/659742 我的操作系统是Win7,使用的VS版本是VS2012,文中的代码都是C#代码. 这几天遇到一个问 ...

  5. listview滚动时背景闪烁,背景黑或白问题解决

    android在使用listview时出现滚动时背景闪烁,变成背景黑或白的问题这样处理: 1:在布局文件中listview标签中加入: android:cacheColorHint="#00 ...

  6. android launcher开发之图标背景以及默认配置

    1:然后我自己看了一下桌面图标的载入过程: 桌面第一次载入时是默认读取一个xml配置文件,完毕配置工作.这个配置文件在Launcher文件夹下, 路径是:\Launcher\res\xml\defau ...

  7. Eclipse自定义启动画面和状态栏图标以及各种小图标的含义

    一. 启动画面自定义 第一种情况:纯Eclipse 找到Eclipse安装路径下\eclipse\plugins\org.eclipse.platform_3.7.2.v201202080800,具体 ...

  8. WPF字体图标——IconFont

    原文:WPF字体图标--IconFont 版权声明:本文为[CSDN博主:松一160]原创文章,未经允许不得转载. https://blog.csdn.net/songyi160/article/de ...

  9. WPF字体图标——FontAwesom

    原文:WPF字体图标--FontAwesom 版权声明:本文为[CSDN博主:松一160]原创文章,未经允许不得转载. https://blog.csdn.net/songyi160/article/ ...

随机推荐

  1. WebGL学习笔记(一)

    作者:朱金灿 来源:http://blog.csdn.net/clever101 (一)WebGL是什么? WebGL是一门在网页上显示三维图形的技术,你可以把它理解为把OpenGL从C/S端搬到了B ...

  2. QGIS中坐标偏移处理

    to_real("LGTD")+(randf(0.0,1.0)-0.5)*2/1000000.0 getRandomValue() import numpy def getRand ...

  3. Python 基于urllib.request封装http协议类

    基于urllib.request封装http协议类 by:授客QQ:1033553122 测试环境: Python版本:Python 3.3   代码实践 #!/usr/bin/env python ...

  4. 高德地图JS API 开发小结

    项目中有一块功能要用到高德地图,所以,想把编码小结一下. 首先是地图的初始化 var map = new AMap.Map("mapDiv", {                  ...

  5. Linux记录屏幕输出log

    应用场景: 请专家通过Console处理问题时,保留console输出无疑是非常有意义的.一来可留着作为维护日志,二来可供事后学习. 最简洁的方式是通过系统自带的script命令去记录. $ scri ...

  6. Navicat连接Oracle 报 ORA-12737 set CHS16GBK错误

            4,680   今天看到0day5上面更新了一个用友ERP的漏洞,确实可以下载任意文件:但是用友ERP基本上都是使用了oracle数据库,必须要有一个好的数据库连接工具才可以,Navi ...

  7. Window 由于未经处理的异常,进程终止。

    今天遇到了一个程序停止的问题: 应用程序: BussinessService.exe Framework 版本: v4.0.30319 说明: 由于未经处理的异常,进程终止.异常信息: System. ...

  8. windows 2003 IIS 设置 FTP被动模式

    IIS FTP 将21端口更改为xx123端口: 更改数据端口: cd c:/Inetpub/AdminScripts cscript.exe adsutil.vbs set /MSFTPSVC/Pa ...

  9. January 07th, 2018 Week 01st Sunday

    To remember is to disengage from the present. 铭记过去就是放弃当下. To remember the past doesn't mean we would ...

  10. Deepin系统安装mysql教程及相关操作

    Deepin系统安装mysql教程及相关操作 1.安装MySQL sudo apt-get install mysql-server,期间需要输入两次密码,root账户的密码. sudo apt-ge ...