Visual Basic Window/Form Routines
FlashWindow: Timing Window Notifications using VB's Timer Control
Posted:   Wednesday October 30, 2002
Updated:   Monday December 26, 2011
Applies to:   VB4-32, VB5, VB6
Developed with:   VB5, Windows XP
OS restrictions:   None
Author:   VBnet - Randy Birch


Pure VB: Cue Banners for the XP Impaired
Manifests: Make the VB IDE use Windows XP Styles
SendMessage: Use Cue Banners to Prompt Users

Shell_NotifyIcon: Windows Systray NOTIFYICONDATA Overview

Shell_NotifyIcon: Add Icon to Windows System Tray
Shell_NotifyIcon: Respond to Systray Icon/Menu Interaction
Shell_NotifyIcon: Respond to Systray Icon/Menu Interaction in a MDI App

Shell_NotifyIcon: Animate the System Tray Icon

FlashWindowEx: Extended Window Notification (Flashing) Options
FlashWindow: Timing Window Notifications using SetTimer
FlashWindow: Timing Window Notifications using VB's Timer Control

Shell_NotifyIcon: Display Systray Balloon Tips
Shell_NotifyIcon: Respond to Systray Balloon Tip Clicks
Shell_NotifyIcon: Use SetTimer to Define Balloon Tip Life

SendMessage: Add Balloon Tips to a Combo Edit Box
SendMessage: Add Balloon Tips to a Text Box


This is pretty close to the minimum code required to flash an application's window or taskbar via the FlashWindow API using VB's intrinsic Timer control.

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 but that it does not currently have the keyboard focus. The FlashWindow function flashes the window only once; for repeated flashing, the application requires calling via a VB or system timer.

When FlashWindow's bInvert parameter is TRUE, the window is flashed from one state to the other. If it is FALSE, the window is returned to its original state (either active or inactive). When an application is minimized and this parameter is TRUE, the taskbar window button flashes active/inactive. If it is FALSE, the taskbar window button flashes inactive, meaning that it does not change colors. It flashes, as if it were being redrawn, but it does not provide the visual invert clue to the user.

With SetTimer, the nIDEvent member specifies a non-zero timer identifier. If the hwnd parameter of SetTimer is null, nIDEvent is ignored. If hwnd is non-null and the window specified by hwnd already has a timer with the value nIDEvent, then the existing timer is replaced by the new timer. When SetTimer replaces a timer, the timer is reset. Therefore, a message will be sent after the current time-out value elapses, but the previously set time-out value is ignored.  The hwnd parameter specifies the handle to the window to be associated with the timer --- this window must be owned by the calling thread. If this parameter is null (0&)  no window is associated with the timer and the nIDEvent parameter is ignored.

 BAS Module Code

 Form Code
Add the following to a form containing a combo (Combo1), a Timer (Timer1) and two command buttons (Command1, Command2):

Option Explicit
' Copyright 1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce 
'               or publish this code on any web site,
'               online service, or distribute as source 
'               on any media without express permission.
Private Declare Function FlashWindow Lib "user32" _
  (ByVal hwnd As Long, _
   ByVal bInvert As Long) As Long

Private Sub Form_Load()

   With Combo1
      .AddItem "50"
      .AddItem "100"
      .AddItem "250"
      .AddItem "500"
      .AddItem "1000"
      .ListIndex = 2
   End With
   Command1.Caption = "Begin Flash"
   Command2.Caption = "Stop Flash"
   Timer1.Enabled = False
End Sub

Private Sub Command1_Click()

   Call FlashBegin(Me.hwnd, Val(Combo1.List(Combo1.ListIndex)))
   Combo1.Enabled = False
   Command1.Enabled = False
End Sub

Private Sub Command2_Click()
   Call FlashEnd(Me.hwnd)
   Command1.Enabled = True
   Combo1.Enabled = True
End Sub

Private Sub FlashBegin(ByVal hwnd As Long, ByVal Frequency As Long)

   If Timer1.Enabled = False Then
      If Frequency > 0 Then
         Timer1.Interval = Frequency
         Timer1.Enabled = True
      End If
   End If

End Sub

Private Sub FlashEnd(ByVal hwnd As Long)

   If Timer1.Enabled Then
      Call FlashWindow(hwnd, False)
      Timer1.Enabled = False
   End If
End Sub

Private Sub Timer1_Timer()

   Call FlashWindow(hwnd, True)

End Sub


PayPal Link
Make payments with PayPal - it's fast, free and secure!


Copyright 1996-2011 VBnet and Randy Birch. All Rights Reserved.
Terms of Use  |  Your Privacy


Hit Counter