How to Create a Flashing Title Bar on a Visual Basic Form

ID Number: Q71280

1.00

WINDOWS

Summary:

When calling a Windows API function call, you can create a flashing

window title bar on the present form or any other form for which you

know the handle.

This information applies to Microsoft Visual Basic Programming System

version 1.00 for Windows.

More Information:

Visual Basic has the ability to flash the title bar on any other 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.

The following section describes how to flash a form while that form

does not have the focus:

1. Create two forms called Form1 and Form2.

2. On Form1, create a timer control and set the Interval Property to

1000. Also set the Enabled Property to FALSE.

3. Within the general-declarations section of Form1, declare the

FlashWindow function as follows:

Declare Function FlashWindow% Lib "user" (ByVal hWnd%,

ByVal bInvert%)

4. Define the following constants directly after the declarations

section:

Const TRUE = -1

Const FALSE = 0

5. In the Form_Load event procedure, add the following code:

Sub Form_Load ()

Form2.Show

End Sub

6. In the Sub_Time1_Timer () procedure of Form1, add the following

code:

Sub Timer1_Timer ()

Succ% = FlashWindow(Form1.hWnd, 1)

End Sub

7. In the GotFocus event procedure of Form1, create the following

code:

Sub Form_GotFocus ()

Timer1.Enabled = 0

End Sub

8. In the Click event for Form2, add the following code:

Sub Form_Click ()

Form1.Timer1.Enabled = -1

End Sub

9. Run the program. Form1 will be in the foreground with Form2 in the

background. Click anywhere on Form2; Form1's Caption Bar will flash

until you click on Form1.

Reference:

1. "Programming Windows: the Microsoft Guide to Writing Applications

for Windows 3," by Charles Petzold (published by Microsoft

Press, 1990)

2. "Microsoft Windows 3.0 Software Development Kit: Reference

Volume 1"

3. The WINSDK.HLP file shipped with Microsoft Windows 3.0 Software

Development Kit.