Method for realizing window flashing based on FlashWindowEx of C Windows API application
- 2021-11-01 04:22:40
- OfStack
In this paper, the method of window flashing based on FlashWindowEx in C # Windows API application is described. Share it for your reference, as follows:
Windows API
Windows, a multi-operating system, not only coordinates the execution of applications, allocates memory, manages resources, It is also a large service center. Calling various services in this service center (each service is a function) can help applications achieve the purposes of opening windows, drawing graphics, using peripheral devices, etc. Because the objects served by these functions are applications (Application), they are called Application Programming Interface, or API functions for short. WIN32 API is the application programming interface for the Microsoft Windows 32-bit platform.
FlashWindowEx
Function Feature: Flash the specified window. It does not change the activation state of the window.
Function prototype:
BOOL WINAPI FlashWindowEx(
__in PFLASHWINFO pfwi
);
Parameter: pfwi Pointer to FLASHWINFO structure. .
Return value: Returns the window state specified before calling the FlashWindowEx function. If the window title is active before the call, the return value is non-zero.
Method for realizing window flashing
API Import
/// <summary>
/// Flashing window
/// </summary>
/// <param name="pwfi"> Window flicker information structure </param>
/// <returns></returns>
[DllImport("user32.dll")]
public static extern bool FlashWindowEx(ref FLASHWINFO pwfi);
Flicker type enumeration definition
/// <summary>
/// Flicker type
/// </summary>
public enum flashType : uint
{
FLASHW_STOP = 0, // Stop flashing
FALSHW_CAPTION = 1, // Only the title flashes
FLASHW_TRAY = 2, // Flash only the taskbar
FLASHW_ALL = 3, // The title and taskbar blink at the same time
FLASHW_PARAM1 = 4,
FLASHW_PARAM2 = 12,
FLASHW_TIMER = FLASHW_TRAY | FLASHW_PARAM1, // Flash the taskbar unconditionally until the send stop flag or the window is activated. If it is not activated, it will be highlighted when it stops
FLASHW_TIMERNOFG = FLASHW_TRAY | FLASHW_PARAM2 // Flash the taskbar when it is not activated until the stop sign is sent or the form is activated, and highlight when it is stopped
}
FLASHWINFO Structure Definition
/// <summary>
/// Contains information about the number of times the system should flicker the window and the flicker state within the specified time
/// </summary>
public struct FLASHWINFO
{
/// <summary>
/// Structure size
/// </summary>
public uint cbSize;
/// <summary>
/// Handle of window to blink or stop
/// </summary>
public IntPtr hwnd;
/// <summary>
/// Type of flicker
/// </summary>
public uint dwFlags;
/// <summary>
/// Number of times the window flashes
/// </summary>
public uint uCount;
/// <summary>
/// Frequency of window flashing, in milliseconds; If the value is 0 Is the flicker frequency of the default icon
/// </summary>
public uint dwTimeout;
}
Packaging by flashing window method
/// <summary>
/// Flashing window
/// </summary>
/// <param name="hWnd"> Window handle </param>
/// <param name="type"> Flicker 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;// Handle to the window to flash, which can be open or minimized
fInfo.dwFlags = (uint)type;// Type of flicker
fInfo.uCount = UInt32.MaxValue;// Number of times the window flashes
fInfo.dwTimeout = 0; // Frequency of window flashing, in milliseconds; If the value is 0 Is the flicker frequency of the default icon
return FlashWindowEx(ref fInfo);
}
For more readers interested in C # related content, please check the topics on this site: "Summary of C # Form Operation Skills", "C # Data Structure and Algorithm Tutorial", "C # Common Control Usage Tutorial", "C # Object-Oriented Programming Introduction Tutorial" and "Summary of Thread Use Skills in C # Programming"
I hope this article is helpful to everyone's C # programming.