Microsoft KB Archive/254339

= How To Use FlashWindowEx to Notify a User from Visual Basic =

Article ID: 254339

Article Last Modified on 7/13/2004

-

APPLIES TO

 Microsoft Visual Basic 5.0 Professional Edition, when used with:  Microsoft Windows 98 Standard Edition

 Microsoft Windows 2000 Standard Edition  Microsoft Visual Basic 6.0 Professional Edition, when used with:  Microsoft Windows 98 Standard Edition

 Microsoft Windows 2000 Standard Edition</li></ul> </li> Microsoft Visual Basic 5.0 Enterprise Edition, when used with:  Microsoft Windows 98 Standard Edition</li></ul>

 Microsoft Windows 2000 Standard Edition</li></ul> </li> Microsoft Visual Basic 6.0 Enterprise Edition, when used with:  Microsoft Windows 98 Standard Edition</li></ul>

 Microsoft Windows 2000 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q254339

<div class="summary_section">

SUMMARY
Under Microsoft Windows 98, Microsoft Windows Me, and Microsoft Windows 2000, a change was made regarding how Windows allows the foreground window to be set. An application is no longer permitted to bring a window to the foreground unless:


 * The application is already the foreground window.


 * The application activated the current foreground window.


 * The application received the last input event.


 * There is currently no active foreground window.


 * The foreground application is being debugged.


 * The foreground lock timeout has expired.

Windows 2000 introduces the following constraint:


 * No menus are active.

This article demonstrates how to implement the new method of alerting a user to an application using the FlashWindowEx API function from Visual Basic. For further information on this topic, see the "References" section below.

<div class="moreinformation_section">

MORE INFORMATION
The following code sample demonstrates how to implement this functionality using Visual Basic versions 5.0 or 6.0. Note that this implementation is intended for Windows 98, Windows Me, and Windows 2000 only. This sample fails on any other operating system.

Step by Step Example
<ol> Start a new Visual Basic Standard EXE project. Form1 is created by default.</li> Add a CommandButton control to Form1.</li>  Add the following code to the General Declarations section of Form1: Option Explicit

Private Declare Function FlashWindowEx Lib "user32" _ (FWInfo As FLASHWINFO) As Boolean

Private Declare Sub Sleep Lib "kernel32" _ (ByVal dwMilliseconds As Long)

Private Type FLASHWINFO cbSize As Long    ' size of structure hWnd As Long      ' hWnd of window to use dwFlags As Long   ' Flags, see below uCount As Long    ' Number of times to flash window dwTimeout As Long ' Flash rate of window in milliseconds. 0 is default. End Type

Const FLASHW_STOP = 0 Const FLASHW_CAPTION = 1 Const FLASHW_TRAY = 2 Const FLASHW_ALL = FLASHW_CAPTION Or FLASHW_TRAY Const FLASHW_TIMER = 4 Const FLASHW_TIMERNOFG = 12

Private Sub Command1_Click Dim RetVal As Integer Dim FWInfo As FLASHWINFO ' Fill the structure: With FWInfo .cbSize = 20 .hWnd = Me.hWnd .dwFlags = FLASHW_ALL .uCount = 5 .dwTimeout = 0 End With ' Allow time to cover the window: Sleep (2000) ' call the function: RetVal = FlashWindowEx(FWInfo) End Sub </li> Start the application and press the CommandButton. A two-second delay occurs before the window flashes in the taskbar. This allows time for you to cover up the window and observe the change in behavior.</li></ol>

<div class="references_section">