代码示例
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;[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);}}}