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:
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.
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
-
Start a new Visual Basic Standard EXE project. Form1 is created by default.
-
Add a CommandButton control to Form1.
-
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
-
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.
Platform SDK Documentation: "Foreground and Background Windows"