Click to Rate and Give Feedback
MSDN
MSDN Library
Diagnostics
Error Handling
 FlashWindowEx Function
FlashWindowEx Function

Flashes the specified window. It does not change the active state of the window.

Syntax

C++
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 clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinuser.h (include Windows.h)
LibraryUser32.lib
DLLUser32.dll

See Also

Error Handling Functions
FLASHWINFO
Notifying the User

Send comments about this topic to Microsoft

Build date: 7/30/2009

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Visual Basic .NET Example of FlashWindowEx      William Vaughn   |   Edit   |   Show History

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.

Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker