Visual Basic


The FlashWindow function does just what it says: it flashes the title bar of a window. If a window is active it flashes inactive, if a window is inactive it flashes active. FlashWindow also flashes the window's taskbar icon. This function is a visual means of attracting attention to a particular window on the screen. The Declare statement for FlashWindow is as follows:

Declare Function FlashWindow Lib "user32" _
      (ByVal hwnd As Long, ByVal dwflags As Long) As Long

You also need to declare whatever constants you'll want to use for the dwflags parameter.

Public Const FLASHW_STOP      As Long = 0
  Public Const FLASHW_CAPTION   As Long = &H1&
  Public Const FLASHW_TRAY      As Long = &H2&
  Public Const FLASHW_TIMER     As Long = &H4&
  Public Const FLASHW_TIMERNOFG As Long = &HC&

The FLASHW constants have the following meanings:

  • FLASHW_STOP: stops the window from flashing and restores it to its original state
  • FLASHW_CAPTION: flashes the title bar on the window
  • FLASHW_TRAY: flashes the button for the given window on the taskbar
  • FLASHW_ALL: flashes the title bar and the taskbar button
  • FLASHW_TIMER: flashes continuously until the FLASHW_STOP flag is set
  • FLASHW_TIMERNOFG: flashes continuously as long as the window is in the background


These flags are actually valid only in Windows 98 and Windows NT 5. In earlier versions of Windows, the second parameter of the FlashWindow call is a Boolean value that determines whether the window should flash (True) or return to its original state (False). However, you don't have to check for the Windows version to use the above flags. Any flag you set other than FLASHW_STOP will be interpreted as True and the window will flash.

The FlashWindowEx Function

The Microsoft Platform SDK includes a function named FlashWindowEx. This function is similar to FlashWindow but it offers much more functionality. FlashWindowEx is part of the Microsoft Platform SDK, which you can download from Microsoft's Web site. FlashWindowEx is available only for Windows 98 and Windows NT 5. The Declare statement for FlashWindowEx looks like this:

Declare Function FlashWindowEx Lib "user32" Alias "FlashWindowEx" _
      (ByVal pfwi As tFLASHWINFO) As Long

You specify the function parameters in a UDT, declared as follows:

      cbSize    As Long
      hwnd      As Long
      dwFlags   As Long
      uCount    As Long
      dwTimeout As Long
  End Type

The first variable in the UDT, cbSize, contains the size of the UDT, Len(cbSize). The next variable contains the window handle for the window you want to flash. The next variable, dwFlags, contains one of the FALSHW flags defined above. The variable uCount specifies the number of times you want to window to flash. The variable dwTimeout contains the rate, in milliseconds, at which you want the window to flash. If you set dwTimeout to 0, the default cursor blink rate will be used.

I've put an example of using this function in the Sound sample. I placed the call within a timer loop so that the window will flash more than once depending on the speed of the system. You can use different types of timing and looping mechanisms if you want the window to flash more than once, but be very careful if you do this. Certain rates of flashing can cause seizures in users suffering from epilepsy. I'm actually not terribly comfortable with the loop I put into the Sounds sample because I haven't placed any restrictions on the actual speed. A flash rate below two hertz is recommended.

by BrainBellupdated