using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
using System.Windows.Interop; public static class FlashWindow
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool FlashWindowEx(ref FLASHWINFO pwfi); [StructLayout(LayoutKind.Sequential)]
private struct FLASHWINFO
{
/// <summary>
/// The size of the structure in bytes.
/// </summary>
public uint cbSize; /// <summary>
/// A Handle to the Window to be Flashed. The window can be either opened or minimized.
/// </summary>
public IntPtr hwnd; /// <summary>
/// The Flash Status.
/// </summary>
public uint dwFlags; /// <summary>
/// The number of times to Flash the window.
/// </summary>
public uint uCount; /// <summary>
/// The rate at which the Window is to be flashed, in milliseconds. If Zero, the function uses the default cursor blink rate.
/// </summary>
public uint dwTimeout;
} /// <summary>
/// Stop flashing. The system restores the window to its original stae.
/// </summary>
public const uint FLASHW_STOP = ; /// <summary>
/// Flash the window caption.
/// </summary>
public const uint FLASHW_CAPTION = ; /// <summary>
/// Flash the taskbar button.
/// </summary>
public const uint FLASHW_TRAY = ; /// <summary>
/// Flash both the window caption and taskbar button.
/// This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
/// </summary>
public const uint FLASHW_ALL = ; /// <summary>
/// Flash continuously, until the FLASHW_STOP flag is set.
/// </summary>
public const uint FLASHW_TIMER = ; /// <summary>
/// Flash continuously until the window comes to the foreground.
/// </summary>
public const uint FLASHW_TIMERNOFG = ; /// <summary>
/// Flash the spacified Window (Form) until it recieves focus.
/// </summary>
/// <param name="form">The Form (Window) to Flash.</param>
/// <returns></returns>
public static bool Flash(Window w)
{
// Make sure we're running under Windows 2000 or later
if (Win2000OrLater)
{
FLASHWINFO fi = Create_FLASHWINFO(new WindowInteropHelper(w).Handle, FLASHW_ALL | FLASHW_TIMERNOFG, uint.MaxValue, );
return FlashWindowEx(ref fi);
}
return false;
} private static FLASHWINFO Create_FLASHWINFO(IntPtr handle, uint flags, uint count, uint timeout)
{
FLASHWINFO fi = new FLASHWINFO();
fi.cbSize = Convert.ToUInt32(Marshal.SizeOf(fi));
fi.hwnd = handle;
fi.dwFlags = flags;
fi.uCount = count;
fi.dwTimeout = timeout;
return fi;
} /// <summary>
/// Flash the specified Window (form) for the specified number of times
/// </summary>
/// <param name="form">The Form (Window) to Flash.</param>
/// <param name="count">The number of times to Flash.</param>
/// <returns></returns>
public static bool Flash(Window w, uint count)
{
if (Win2000OrLater)
{
FLASHWINFO fi = Create_FLASHWINFO(new WindowInteropHelper(w).Handle, FLASHW_ALL, count, );
return FlashWindowEx(ref fi);
}
return false;
} /// <summary>
/// Start Flashing the specified Window (form)
/// </summary>
/// <param name="form">The Form (Window) to Flash.</param>
/// <returns></returns>
public static bool Start(Window w)
{
if (Win2000OrLater)
{
var fi = Create_FLASHWINFO(new WindowInteropHelper(w).Handle, FLASHW_ALL, uint.MaxValue, );
return FlashWindowEx(ref fi);
}
return false;
} /// <summary>
/// Stop Flashing the specified Window (form)
/// </summary>
/// <param name="form"></param>
/// <returns></returns>
public static bool Stop(Window w)
{
if (Win2000OrLater)
{
var fi = Create_FLASHWINFO(new WindowInteropHelper(w).Handle, FLASHW_STOP, uint.MaxValue, );
return FlashWindowEx(ref fi);
}
return false;
} /// <summary>
/// A boolean value indicating whether the application is running on Windows 2000 or later.
/// </summary>
private static bool Win2000OrLater
{
get { return System.Environment.OSVersion.Version.Major >= ; }
}
}

FlashWindow

启动:FlashWindow.Start(Window w);

停止:FlashWindow.Stop(Window w);

.NET技术交流群 199281001 .欢迎加入。

WPF 任务栏图标闪烁提醒的更多相关文章

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

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

  2. VC 任务栏图标闪烁

    像QQ来消息时的,图标闪烁效果 将如下代码添加到Timer响应函数中 ) {// 任务栏图标闪烁 if (this != GetForegroundWindow()) { //// this-> ...

  3. WPF 系统托盘 图标闪烁

    WPF消息通知 系统托盘,图标闪烁 using System.Windows.Forms; using System.Windows.Threading; public partial class W ...

  4. wpf 状态栏图标背景闪烁提醒 FlashWindowEx

    原文:wpf 状态栏图标背景闪烁提醒 FlashWindowEx using System; using System.Runtime.InteropServices; using System.Wi ...

  5. WPF——TaskBarIconOverlay(任务栏图标叠加)

    原文:WPF--TaskBarIconOverlay(任务栏图标叠加) <Window.Resources> <DrawingImage x:Key="OverlayIma ...

  6. C#:实现托盘(任务栏图标与托盘图标互斥)

    实现托盘(任务栏图标与托盘图标互斥),并且在点击任务栏图标时实现的最小化与点击最小化按钮分离. 具体如下: 1.向窗体上添加如下控件:MenuStrip menuStrip1, NotifyIcon ...

  7. WPF 任务栏颜色 - 简书

    原文:WPF 任务栏颜色 - 简书 先看看效果,这种效果可以用来做进度条或者消息通知闪烁.   image.png   image.png   image.png   image.png 有一个好消息 ...

  8. C# 程序启动最小化至任务栏及闪烁

    主要功能: C#让窗体最小化至任务栏,同时在系统托盘区的图标点击左键能显示窗体,并使窗体闪烁. 首先: 创建窗体应用程序,并添加控件NotifyIcon及ContextMenuStrip控件 Noti ...

  9. WPF 4 动态覆盖图标(Dynamic Overlay Icon)

    原文:WPF 4 动态覆盖图标(Dynamic Overlay Icon)      在<WPF 4 开发Windows 7 任务栏>一文中我们学习了任务栏的相关开发内容,同时也对覆盖图标 ...

随机推荐

  1. Android 编程下 Touch 事件的分发和消费机制

    Android 中与 Touch 事件相关的方法包括:dispatchTouchEvent(MotionEvent ev).onInterceptTouchEvent(MotionEvent ev). ...

  2. LeetCode 笔记24 Palindrome Partitioning II (智商碾压)

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...

  3. iOS——数据安全性问题小结

    在移动互联网快速发展的今天,iOS应用直接运行在用户的手机上,与运行在服务器后台服务相比,更有可能被黑客攻击. a.网络安全: 1.1 安全地传输用户密码 事先生成一对用于加密的公私钥,客户端登录的时 ...

  4. IOS开发之—— iOS 支付 [支付宝、银联、微信]

    支付宝iOSsdk官方下载sdk地址:https://b.alipay.com/order/productDetail.htm?productId=2013080604609654&tabId ...

  5. I2C和LCD信号干扰的解决:硬件工程师都硬不起来,让软件工程师硬着头上

    DEMO4,LCD的clk干扰I2C,I2C无法通信. 把排针压下,去掉LCD的CLK,恢复正常.     过程: 直接跳线I2C,没问题.两排针插到一起就无法通信. 一个个的排针去除,最终找到LCD ...

  6. C/C++程序从编译到链接的过程

    编译器是一个神奇的东西,它能够将我们所编写的高级语言源代码翻译成机器可识别的语言(二进制代码),并让程序按照我们的意图按步执行.那么,从编写源文件代码到可执行文件,到底分为几步呢?这个过程可以总结为以 ...

  7. IT男的”幸福”生活"续7

    哇,兄弟们的热情真牛X的高呀!!! 在这里谢谢大家了.同时祝大家元宵节快乐,幸福美好.呵呵. 续7准备开始了… ….. 是什么样的事困扰她了… 躺在床上我,一直回想着MM,今天的情绪状态. 分析一下: ...

  8. Bootstrap2和3的区别

    如果你需要兼容IE8甚至是IE7和IE6,那么只能选择Bootstrap2,虽然它自身在IE6的效果也并不完美.     但是倘若你跟随时代的脚步,并且面向的客户也很高端大气上档次地选择只需要兼容高级 ...

  9. G-nav-02

    /*header: Navigation public style*/header:before, header:after ,.navigation:before, .navigation:afte ...

  10. Java设计模式-抽象工厂模式(Abstract Factory )

    工厂方法模式有一个问题就是,类的创建依赖工厂类,也就是说,如果想要拓展程序,必须对工厂类进行修改,这违背了闭包原则,所以,从设计角度考虑,有一定的问题,如何解决?就用到抽象工厂模式,创建多个工厂类,这 ...