Microsoft KB Archive/147815

= How To Create a Flashing Title Bar on a Visual Basic Form =

Article ID: 147815

Article Last Modified on 6/29/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q147815



SUMMARY
With the FlashWindow Windows API function, you can create a flashing window title bar for any window for which you know the window handle.



MORE INFORMATION
Visual Basic for Windows has the ability to flash the title bar on any form if you can get the handle to that form. The function FlashWindow flashes the specified window once. Flashing a window means changing the appearance of its caption bar, as if the window were changing from inactive to active status, or vice versa. (An inactive caption bar changes to an active caption bar; an active caption bar changes to an inactive caption bar.)

Typically, a window is flashed to inform the user that the window requires attention when that window does not currently have the input focus. The function FlashWindow is defined as

FlashWindow(hWnd, bInvert)

where:

  hWnd      - Identifies the window to be flashed. The window can be              either open or iconic.

bInvert  - Specifies whether the window is to be flashed or               returned to its original state. The window is flashed from one state to the other if the bInvert parameter is              nonzero. If the bInvert parameter is zero, the window is returned to its original state (either active or              inactive).

FlashWindow returns a value that specifies the window's state before the call to the FlashWindow function. It is nonzero if the window was active before the call; otherwise, it is zero.

When using FlashWindow, it is a good design practice to set the flash rate equal to that of the caret rate. The caret blink rate can be found by using the GetCaretBlinkTime function. GetCaretBlinkTime returns the elapsed time, in milliseconds, required to cause the caret to blink.

Step-by-Step Example
The following section describes how to flash a form while that form does not have the focus:

 Start and new project in Visual Basic. Form1 is created by default. Add a Timer control to the Form1 form.  Copy the following code to the Code window of the Form1 form: Private Sub Form_GotFocus Timer1.Enabled = False End Sub

Private Sub Form_Load Timer1.Interval = GetCaretBlinkTime Form2.Show End Sub

Private Sub Timer1_Timer Success = FlashWindow(Form1.hwnd, 1) End Sub

 Add a second form to the project.  Copy the following code to the Code window of the Form2 form: Private Sub Form_Click Form1.Timer1.Enabled = True End Sub

 Add a module to the project.</li>  Copy the following code to the Code window of the Module1 module: 'Depending on what operating system you are using determines the 'correct function declares and variables. This is an example of  'conditional compilation.

#If Win32 Then

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

Declare Function GetCaretBlinkTime Lib "user32" As Long

Dim Success As Long

#Else Declare Function FlashWindow Lib "User" ( _                      ByVal hwnd As Integer, _                       ByVal bInvert As Integer) As Integer

Declare Function GetCaretBlinkTime Lib "User" As Integer

Dim Success As Integer

#End If

</li> On the Run menu, click Start or press the F5 key to start the program. Form1 will be in the foreground with Form2 in the background. Click anywhere in Form2; Form1's Caption Bar will flash until you click Form1.</li></ol>

Keywords: kbhowto KB147815

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.