In addition to coordinating the execution of applications, allocating memory, and managing resources, Windows, a multi-operating system, is also a large The service center calls various services of this service center (each service is a function), which can help the application to open windows, draw graphics, use peripheral devices, etc., because the objects served by these functions are applications (Application ), so it is called Application Programming Interface, or API function for short. WIN32 API is the application programming interface of the Microsoft Windows 32-bit platform.
Function: Flash the specified window. It does not change the activation state of the window.
Function prototype: BOOL WINAPI FlashWindowEx(
__in PFLASHWINFO pfwi
);
Parameters: pfwi is a pointer to the FLASHWINFO structure. .
Return value: Returns the specified window state before calling the FlashWindowEx function. If the window title was active before the call, the return value is non-zero.
/// <summary> /// 闪烁窗口 /// </summary> /// <param name="pwfi">窗口闪烁信息结构</param> /// <returns></returns> [DllImport("user32.dll")] public static extern bool FlashWindowEx(ref FLASHWINFO pwfi);
/// <summary> /// 闪烁类型 /// </summary> public enum flashType : uint { FLASHW_STOP = 0, //停止闪烁 FALSHW_CAPTION = 1, //只闪烁标题 FLASHW_TRAY = 2, //只闪烁任务栏 FLASHW_ALL = 3, //标题和任务栏同时闪烁 FLASHW_PARAM1 = 4, FLASHW_PARAM2 = 12, FLASHW_TIMER = FLASHW_TRAY | FLASHW_PARAM1, //无条件闪烁任务栏直到发送停止标志或者窗口被激活,如果未激活,停止时高亮 FLASHW_TIMERNOFG = FLASHW_TRAY | FLASHW_PARAM2 //未激活时闪烁任务栏直到发送停止标志或者窗体被激活,停止后高亮 }
/// <summary> /// 包含系统应在指定时间内闪烁窗口次数和闪烁状态的信息 /// </summary> public struct FLASHWINFO { /// <summary> /// 结构大小 /// </summary> public uint cbSize; /// <summary> /// 要闪烁或停止的窗口句柄 /// </summary> public IntPtr hwnd; /// <summary> /// 闪烁的类型 /// </summary> public uint dwFlags; /// <summary> /// 闪烁窗口的次数 /// </summary> public uint uCount; /// <summary> /// 窗口闪烁的频度,毫秒为单位;若该值为0,则为默认图标的闪烁频度 /// </summary> public uint dwTimeout; }
/// <summary> /// 闪烁窗口 /// </summary> /// <param name="hWnd">窗口句柄</param> /// <param name="type">闪烁类型</param> /// <returns></returns> public static bool FlashWindowEx(IntPtr hWnd, flashType type) { FLASHWINFO fInfo = new FLASHWINFO(); fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo)); fInfo.hwnd = hWnd;//要闪烁的窗口的句柄,该窗口可以是打开的或最小化的 fInfo.dwFlags = (uint)type;//闪烁的类型 fInfo.uCount = UInt32.MaxValue;//闪烁窗口的次数 fInfo.dwTimeout = 0; //窗口闪烁的频度,毫秒为单位;若该值为0,则为默认图标的闪烁频度 return FlashWindowEx(ref fInfo); }
The above is the detailed content of C# WindowsAPI application FlashWindowEx - Detailed explanation of the method of realizing window flashing. For more information, please follow other related articles on the PHP Chinese website!