原文: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. 为什么 C# 比 C++ 编译快那么多

    Go 我不懂,下面以 C++ 和 C# 对比来说明为什么 C++ 编译慢和 C# 编译快. C 和 C++ 文件的编译经过几个主要步骤: 处理续行符处理(“\”)之类的杂事 词法分析,解析出 toke ...

  2. Tsung CentOS 操作系统下搭建tsung性能测试环境_Part 1

    CentOS 操作系统下搭建tsung性能测试环境_Part 1 by:授客 QQ:1033553122 步骤1.下载软件安装包 CentOS-6.0-x86_64-bin-DVD1.iso jdk- ...

  3. HBuilder开发ios App离线打包启动画面无效的解决方法

    其中容易忽略的一点是manifest.json文件.plus下加入如下配置: "splashscreen": { "autoclose": false,/*如果 ...

  4. Linux : Vim 使用与配置 (附 GitHub 自动化配置脚本)

    由于经常使用 vim 编辑配置文件,有时候也会进行使用vim 编写一些脚本和c/c++ 程序,所以配置一个常用的 vim 是很是必要的.这篇博文主要是记录vim使用和配置相关的一些知识点. 关于vim ...

  5. 关掉 ubuntu bug 报告功能

    想关掉这个: 通过服务加配置文件关掉

  6. Centos7系统详细的启动流程

    熟悉系统启动流程对于我们学习Linux系统是非常有帮助的,虽然基础,但能帮助我们更加理解Linux系统的工作机制.以下将以CentOS发行版为例来介绍Linux系统的启动流程,因为在CentOS 5. ...

  7. Hadoop2.7.6_03_HDFS原理

    1. HDFS前言 l  设计思想 分而治之:将大文件.大批量文件,分布式存放在大量服务器上,以便于采取分而治之的方式对海量数据进行运算分析: l  在大数据系统中作用: 为各类分布式运算框架(如:m ...

  8. 关于C语言学习的一些感想(初学者)

    C语言是一门通用计算机编程语言,广泛应用于底层开发.C语言的设计目标是提供一种能以简易的方式编译.处理低级存储器.产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言. 尽管C语言提供了许多低 ...

  9. JAVA基础-栈与堆,static、final修饰符、内部类和Java内存分配

    Java栈与堆 堆:顺序随意 栈:后进先出(Last-in/First-Out). Java的堆是一个运行时数据区,类的对象从中分配空间.这些对象通过new.newarray.anewarray和mu ...

  10. 习题 6 字符串(string)和文本

    虽然你已经在程序中写过字符串了,你还没学过它们的用处.在这章习题中我们将使用复杂的字符串来建立一系列的变量,从中你将学到它们的用途.首先我们解释一下字符串是什么 东西. 字符串通常是指你想要展示给别人 ...