WPF中的图标闪烁功能

代码示例

cs 复制代码
using System.Runtime.InteropServices;
using System.Windows.Interop;
using System.Windows;


namespace AutoFeed.ViewModel
{
    // 用于存储窗口闪烁信息的结构体
    [StructLayout(LayoutKind.Sequential)]
    public struct FLASHWINFO
    {
        public uint cbSize;         // 结构体大小
        public IntPtr hwnd;         // 窗口句柄
        public uint dwFlags;        // 闪烁标志
        public uint uCount;         // 闪烁次数
        public uint dwTimeout;      // 闪烁间隔时间
    }

    public class API
    {
        
         // 同时闪烁窗口标题和任务栏按钮
         public const uint FLASHW_ALL = 3;

         // 持续闪烁直到窗口激活
         public const uint FLASHW_TIMERNOFG = 12;

         // 调用Windows API实现窗口闪烁
         [DllImport("user32.dll")]
         [return: MarshalAs(2)]
         public static extern bool FlashWindowEx(ref FLASHWINFO pwfi);

         // 开始闪烁窗口
         public static void FlashWindow(Window window)
         {
             // 获取窗口句柄
             WindowInteropHelper h = new WindowInteropHelper(window);

             // 初始化闪烁信息
             FLASHWINFO info = new FLASHWINFO
             {
                 hwnd = h.Handle,
                 dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG, // 同时闪烁标题和任务栏,直到窗口激活
                 uCount = uint.MaxValue,  // 无限次数
                 dwTimeout = 0            // 使用默认间隔
             };

             // 设置结构体大小
             info.cbSize = Convert.ToUInt32(Marshal.SizeOf(info));
             // 启动闪烁
             FlashWindowEx(ref info);
        }

         // 停止闪烁窗口
         public static void StopFlashingWindow(Window window)
         {
             WindowInteropHelper h = new WindowInteropHelper(window);

             FLASHWINFO info = new FLASHWINFO
             {
                 hwnd = h.Handle,
                 dwFlags = 0,             // 停止闪烁的标志
                 uCount = uint.MaxValue,
                 dwTimeout = 0
             };

             info.cbSize = Convert.ToUInt32(Marshal.SizeOf(info));
             // 停止闪烁
             FlashWindowEx(ref info);
         }
    }
    
}
相关推荐
dujunqiu2 小时前
S32DS上进行S32K328的时钟配置,LPUART时钟配置步骤详解
单片机·mcu
Peter_Deng.5 小时前
单片机 - STM32F407 ADC 模式详解:单次转换、连续转换、扫描模式、非扫描模式
stm32·单片机·嵌入式硬件
iFulling5 小时前
【单片机】51单片机练习代码
单片机·嵌入式硬件·51单片机
华普微HOPERF7 小时前
让温度“说话”,数字温度传感器如何智能感知温度?
科技·单片机·嵌入式硬件·物联网·智能家居
iCxhust7 小时前
PC16550 UART接收中断处理完整示例代码
c语言·开发语言·stm32·单片机·嵌入式硬件
NEWEVA__zzera227 小时前
记录存储的使用
经验分享·单片机
iFulling8 小时前
【单片机】51单片机学习笔记
单片机·学习·51单片机
YONYON-R&D9 小时前
STM32L431中,低功耗模式下的仿真调试功能受到限制
单片机·嵌入式硬件
甄天10 小时前
WPF数据绑定
c#·wpf
起个网名真难~11 小时前
HAL库STM32中使用printf打印数据到串口
stm32·单片机·嵌入式硬件