Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

FlashWindowEx (user32)
 
.
Summary

C# Signature:

[DllImport("user32.dll")]
static extern Int32 FlashWindowEx(ref FLASHWINFO pwfi);

User-Defined Types:

[StructLayout(LayoutKind.Sequential)]
public struct FLASHWINFO
{
    public UInt32 cbSize;
    public IntPtr hwnd;
    public UInt32 dwFlags;
    public UInt32 uCount;
    public UInt32 dwTimeout;
}

Notes:

//Stop flashing. The system restores the window to its original state.
public const UInt32 FLASHW_STOP = 0;
//Flash the window caption.
public const UInt32 FLASHW_CAPTION = 1;
//Flash the taskbar button.
public const UInt32 FLASHW_TRAY = 2;
//Flash both the window caption and taskbar button.
//This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
public const UInt32 FLASHW_ALL = 3;
//Flash continuously, until the FLASHW_STOP flag is set.
public const UInt32 FLASHW_TIMER = 4;
//Flash continuously until the window comes to the foreground.
public const UInt32 FLASHW_TIMERNOFG = 12;

Tips & Tricks:

Please add some!

Sample Code:

/// <summary>
/// Flashes a window
/// </summary>
/// <param name="hWnd">The handle to the window to flash</param>
/// <returns>whether or not the window needed flashing</returns>
public static bool FlashWindowEx(IntPtr hWnd)
{
    FLASHWINFO fInfo = new FLASHWINFO();

    fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
    fInfo.hwnd = hWnd;
    fInfo.dwFlags = FLASHW_ALL;
    fInfo.uCount = UInt32.MaxValue;
    fInfo.dwTimeout = 0;

    return (FlashWindowEx(ref fInfo) == 0);
}

...

/// Minor adjust to the code above
/// <summary>
/// Flashes a window until the window comes to the foreground
/// Receives the form that will flash
/// </summary>
/// <param name="hWnd">The handle to the window to flash</param>
/// <returns>whether or not the window needed flashing</returns>
public static bool FlashWindowEx(Form frm)
{
        IntPtr hWnd = Frm.Handle;
        FLASHWINFO fInfo = new FLASHWINFO();

        fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
        fInfo.hwnd = hWnd;
        fInfo.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
        fInfo.uCount = UInt32.MaxValue;
        fInfo.dwTimeout = 0;

        return (FlashWindowEx(ref fInfo) == 0);
}

Alternative Managed API:

Do you know one? Please contribute it!

Documentation

VB Code:

#Region " Flash Window Routines"

  Private Declare Function FlashWindowEx Lib "User32" (ByRef FWInfo As FLASHWINFO) As Int32

  Private Const FLASHW_STOP As Int32 = 0
  Private Const FLASHW_CAPTION As Int32 = &H1&
  Private Const FLASHW_TRAY As Int32 = &H2&
  Private Const FLASHW_ALL As Int32 = FLASHW_CAPTION Or FLASHW_TRAY
  Private Const FLASHW_TIMER As Int32 = &H4&
  Private Const FLASHW_TIMERNOFG As Int32 = &HC&

  Private Structure FLASHWINFO
    Dim cbSize As Int32
    Dim hwnd As IntPtr
    Dim dwFlags As Int32
    Dim uCount As Int32
    Dim dwTimeout As Int32
  End Structure

  Public Shared Function FlashWindow(ByRef frm As Form) As Int32
    Return FlashWindow(frm, True, True, 5)
  End Function
  Public Shared Function FlashWindow(ByRef frm As Form, ByVal FlashTitleBar As Boolean, ByVal FlashTray As Boolean) As Int32
    Return FlashWindow(frm, FlashTitleBar, FlashTray, 5)
  End Function
  Public Shared Function FlashWindow(ByRef frm As Form, ByVal NumTimes2Flash As Integer) As Int32
    Return FlashWindow(frm, True, True, NumTimes2Flash)
  End Function
  Public Shared Function FlashWindow(ByRef frm As Form, ByVal FlashTitleBar As Boolean, ByVal FlashTray As Boolean, ByVal NumTimes2Flash As Integer) As Int32
    Try
      Dim fwi As New FLASHWINFO
      With fwi
    .cbSize = System.Runtime.InteropServices.Marshal.SizeOf(fwi)
    .hwnd = IIf(frm Is Nothing, 0, frm.Handle)
    If FlashTitleBar Then .dwFlags = .dwFlags Or FLASHW_CAPTION
    If FlashTray Then .dwFlags = .dwFlags Or FLASHW_TRAY
    .uCount = NumTimes2Flash
    .dwTimeout = 250
      End With
      Return FlashWindowEx(fwi)
    Catch
      Return -1
    End Try
  End Function

#End Region

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions