FlashWindowEx function
Applies to: desktop apps only
Flashes the specified window. It does not change the active state of the window.
Syntax
BOOL WINAPI FlashWindowEx( __in PFLASHWINFO pfwi );
Parameters
- pfwi [in]
-
A pointer to a FLASHWINFO structure.
Return value
The return value specifies the window's state before the call to the FlashWindowEx function. If the window caption was drawn as active before the call, the return value is nonzero. Otherwise, the return value is zero.
Remarks
Typically, you flash a window to inform the user that the window requires attention but does not currently have the keyboard focus. When a window flashes, it appears to change from inactive to active status. An inactive caption bar changes to an active caption bar; an active caption bar changes to an inactive caption bar.
Requirements
|
Minimum supported client | Windows XP |
|---|---|
|
Minimum supported server | Windows Server 2003 |
|
Header |
|
|
Library |
|
|
DLL |
|
See also
Send comments about this topic to Microsoft
Build date: 3/6/2012
- 2/12/2012
- Mark D. Rejhon
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool FlashWindowEx(ref FLASHWINFO pwfi);
[StructLayout(LayoutKind.Sequential)]
public 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 FlashWindowFlags dwFlags; //uint
/// <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;
}
public enum FlashWindowFlags : uint
{
/// <summary>
/// Stop flashing. The system restores the window to its original state.
/// </summary>
FLASHW_STOP = 0,
/// <summary>
/// Flash the window caption.
/// </summary>
FLASHW_CAPTION = 1,
/// <summary>
/// Flash the taskbar button.
/// </summary>
FLASHW_TRAY = 2,
/// <summary>
/// Flash both the window caption and taskbar button.
/// This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
/// </summary>
FLASHW_ALL = 3,
/// <summary>
/// Flash continuously, until the FLASHW_STOP flag is set.
/// </summary>
FLASHW_TIMER = 4,
/// <summary>
/// Flash continuously until the window comes to the foreground.
/// </summary>
FLASHW_TIMERNOFG = 12
}
public static bool FlashWindow(IntPtr hWnd,
FlashWindowFlags fOptions,
uint FlashCount,
uint FlashRate)
{
if(IntPtr.Zero != hWnd)
{
FLASHWINFO fi = new FLASHWINFO();
fi.cbSize = (uint)Marshal.SizeOf(typeof(FLASHWINFO));
fi.dwFlags = fOptions;
fi.uCount = FlashCount;
fi.dwTimeout = FlashRate;
fi.hwnd = hWnd;
return FlashWindowEx(ref fi);
}
return false;
}public static bool StopFlashingWindow(IntPtr hWnd)
{
if(IntPtr.Zero != hWnd)
{
FLASHWINFO fi = new FLASHWINFO();
fi.cbSize = (uint)Marshal.SizeOf(typeof(FLASHWINFO));
fi.dwFlags = (uint)FlashWindowFlags.FLASHW_STOP;
fi.hwnd = hWnd;
return FlashWindowEx(ref fi);
}
return false;
}
- 6/30/2010
- Se7en Soft
- 6/30/2010
- Se7en Soft
While writing an application to monitor LAN and WAN availability I was forced to use this API to flash the minimized Window icon in the task bar. Note that the NotifyIcon is also useful for notifying the user that an application needs their attention. Here is a class built from a suggestion by a fellow MVP (Rob Teixeira) that does the trick. I encapsulated it in a class to make it easier to integrate into an application. Note that I used an enumeration that the developer using the class will be able to see when coding a call to the FlashWindow method. The code to call the class is shown below.
_______________________________________________________
Imports System.Runtime.InteropServices
Public Class FlashWindow
Public Enum enuFlashOptions As UInteger
FLASHW_ALL = &H3 ' Flash both the window caption and taskbar button.
' This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
FLASHW_CAPTION = &H1 ' Flash the window caption.
FLASHW_STOP = 0 ' Stop flashing. The system restores the window to its original state.
FLASHW_TIMER = &H4 ' Flash continuously, until the FLASHW_STOP flag is set.
FLASHW_TIMERNOFG = &HC ' Flash continuously until the window comes to the foreground.
FLASHW_TRAY = &H2
End Enum
Public Structure FlashWindowInfo
Public cbSize As Integer
Public hwnd As IntPtr
Public dwFlags As UInteger
Public uCount As UInteger
Public dwTimeout As UInteger
End Structure
Declare Function FlashWindowEx Lib "user32.dll" (ByRef pInfo As FlashWindowInfo) As Boolean
Public Sub FlashWindow(ByVal frmForm As Form, _
ByVal FlashWindowInfoFlags As enuFlashOptions, _
Optional ByVal intFlashTimes As UInteger = 5)
If (frmForm.WindowState = FormWindowState.Minimized) Or FlashWindowInfoFlags = enuFlashOptions.FLASHW_STOP Then
Dim info As FlashWindowInfo
With info
.cbSize = Marshal.SizeOf(info)
.dwFlags = FlashWindowInfoFlags ' See enumeration for flag values
.dwTimeout = 0 'Flash rate in ms or default cursor blink rate
.hwnd = frmForm.Handle()
.uCount = intFlashTimes ' Number of times to flash
End With
FlashWindowEx(info)
End If
End Sub
End Class
Yes, this is in VB.NET. Get over it.
______________________________________
The code to invoke the class is as follows:
' Start flashing the program icon (if form is minimized)
Dim fwFlash As New FlashWindow
If Me.WindowState = FormWindowState.Minimized Then
' Flash minimized window
fwFlash.FlashWindow(Me, FlashWindow.enuFlashOptions.FLASHW_ALL, 9999)
End If
hth
See www.hitchhikerguides.net or www.betav.com/blog/billva FMI on my books and speaking tour.
- 9/5/2008
- William Vaughn