原文: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. python装饰器(新年第一写)

    祭奠碌碌无为的2018,想想其实也不算碌碌无为,至少我还搞懂了装饰器,写了一堆有用没用的玩意 原来觉得装饰器挺难的,直到2018年的最后几天,突然就明白了,难道这就是传说中的开天聪么 言归正传,之所以 ...

  2. [MapReduce_5] MapReduce 中的 Combiner 组件应用

    0. 说明 Combiner 介绍 &&  在 MapReduce 中的应用 1. 介绍 Combiner: Map 端的 Reduce,有自己的使用场景 在相同 Key 过多的情况下 ...

  3. January 15th, 2018 Week 03rd Monday

    We got things to do. Places to go. People to see. Futures to make. 我们有很多事情要做,有很多地方要去,有很多人要见,有很多美好的未来 ...

  4. python基础 - 字符串作

    split(sep=None, maxsplip=-1) 从左到右 sep 指定分隔字符串,缺省情况下空白字符串,指定的字符串会被切掉 maxsplit 指定分隔次数,-1 表示遍历 rsplit(s ...

  5. VS code 修改主题设置代码对其齐线

    用VS Code 写代码的时候有时候缩进太多就不知道对应的是哪一个标签了,那么可不可以让它显示缩进参考线,这样就清楚的多了.答案是肯定的,方法如下: 找到 文件-->首选项——>设置→搜索 ...

  6. 控件_AnalogClock

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...

  7. sed命令替换字符包含斜杠\,引号的处理方法

    在字符替换中,可能会遇见引号,“/”等的替换,这时应该注意,sed的命令原型是: sed -i  "s/oldstring/goalstring/g" file 如果一个路径是da ...

  8. 2018-2019-2 网络对抗技术 20165318 Exp6 信息搜集与漏洞扫描

    2018-2019-2 网络对抗技术 20165318 Exp6 信息搜集与漏洞扫描 原理与实践说明 实践原理 实践内容概述 基础问题回答 实践过程记录 各种搜索技巧的应用 DNS IP注册信息的查询 ...

  9. Myeclipse 启动报错 Failed to create the java Virtual Machine

    1.找到Myeclipse的安装目录 2.找到myeclipse.ini文件 3.打开myeclipse文件 你把原来的jvm.dll文件路径配置改成你的jdk安装路径中的jvm.dll路径 即: C ...

  10. 转载 JavaScript的函数声明与函数表达式的区别

    1)函数声明(Function Declaration); // 函数声明 function funDeclaration(type){ return type==="Declaration ...