VB3 How to Create a Flashing Title Bar on a VB Form

ID: Q71280


The information in this article applies to:


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.

***WARNING: The flash rate should be set based on the caret blink rate. Then, application users who have epilepsy can control the flash rate so they don't have a seizure.***


MORE INFORMATION

Visual Basic for Windows 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:
    
       ' The following Declare statement must appear on one line.
    
       Declare Function FlashWindow% Lib "user" (ByVal hWnd%,
                                                    ByVal bInvert%)
     


  4. In Visual Basic version 1.0 for Windows, define the following constants in 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 Timer1_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 =  False
       End Sub
     


  8. In the Click event for Form2, add the following code:
    
       Sub Form_Click ()
          Form1.Timer1.Enabled = True
       End Sub
     


  9. Run 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.


Additional query words: 2.00 3.00 vb3only


Keywords          : kbcode kbWndw 
Version           : 1.00 2.00 3.00
Platform          : WINDOWS 
Issue type        : 

Last Reviewed: June 22, 1999