Visual Basic Window/Form Routines
FlashWindowEx: Extended Window Notification (Flashing) Options
     
Posted:   Wednesday October 30, 2002
Updated:   Monday December 26, 2011
     
Applies to:   VB4-32, VB5, VB6
Developed with:   VB5, Windows XP
OS restrictions:   Windows 98, Windows 2000, Windows XP, .Net Server
Author:   VBnet - Randy Birch
     

Related:  

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

     
 Prerequisites
OS restrictions above.

As with most of Windows' Ex-flavour APIs, FlashWindowEx provides extended functionality over the older FlashWindow call. Through the FLASHWINFO structure you can control the type of flashing :
  • "normal" mode, simulating FlashWindow's behaviour and  requiring an explicit command to stop (you call FlashWindowEx again with the FLASHW_STOP message)
  • "by duration", where the window/taskbar flashes for a specific number of times as indicated by the uCount parameter of FLASHWINFO at the interval specified
  • "until activated", where the window continues flashing until it becomes the active window.

In addition, each one of these modes provides for the flash-interval to be specified, as well as specifying whether the flashing object should be the on-screen window, the taskbar entry, or both.  Like FlashWindow, FlashWindowEx does not affect an applications icon that may reside in the systray area of the taskbar; the code for animating the systray icon that could be used in conjunction with FlashWindowEx is listed under the Related items above.

Due to the number of options available, I chose to break up the visual look of the demo form using frames. These are strictly for clarity and serve no purpose to the actual demo of the routines. If you're interested in replicating the above, Combo1 is at the top, Command1 and Command2 are in frame 1, Command 3 and Combo2 are in frame 2, and Command 4 and Combo 3 are in frame 3.

When the Until Activated option is selected, the "Flashes until freeze" value represents the number of flashes that will occur before the taskbar item "stays on" (stops flashing in a highlighted state).  I've discovered that by passing -1, the flashing will continue until the application is activated. At a value > 0, the item will flash and then "freeze on".

Note as well that the demo builds a flag to demonstrate selectively flash the window or the taskbar item.  In practical use where you may want to flash both, the provided constant FLASHW_ALL can be used in place of FLASHW_FLAGS and/or FLASHW_CAPTION and FLASHW_TRAY.

 BAS Module Code
None.

 Form Code
Add the following to a form containing a three combo boxes (Combo1, Combo2, Combo3), four command buttons (Command1 through Command4, and two check boxes (Check1, Check2):

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.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Stop flashing. The system restores the
'window to its original state
Private Const FLASHW_STOP As Long = 0

'Flash the window caption
Private Const FLASHW_CAPTION As Long = &H1

'Flash the taskbar button
Private Const FLASHW_TRAY As Long = &H2

'Flash both the window caption and taskbar button
Private Const FLASHW_ALL As Long = (FLASHW_CAPTION Or FLASHW_TRAY)

'Flash continuously, until the FLASHW_STOP flag is set
Private Const FLASHW_TIMER As Long = &H4

'Flash continuously until the window comes
'to the foreground
Private Const FLASHW_TIMERNOFG As Long = &HC

Private FLASHW_FLAGS As Long

Private Type FLASHWINFO
   cbSize As Long
   hwnd As Long
   dwFlags As Long
   uCount As Long
   dwTimeout As Long
End Type

Private Declare Function FlashWindowEx Lib "user32" _
  (pflashwininfo As FLASHWINFO) As Long


Private Sub Form_Load()

   Dim cnt As Long
   
   With Combo1
      .AddItem "0  (default cursor rate)"
      .AddItem "50"
      .AddItem "100"
      .AddItem "250"
      .AddItem "500"
      .AddItem "1000"
      .ListIndex = 0
   End With
   
   With Combo2
      For cnt = 5 To 100 Step 5
         .AddItem cnt
      Next
      
      .ListIndex = 0
   
   End With
   
   With Combo3
   
      .AddItem "-1"
      .AddItem "0"
      
      For cnt = 5 To 100 Step 5
         .AddItem cnt
      Next
      
      .ListIndex = 0
   
   End With
   
   Command1.Caption = "Begin Flash"
   Command2.Caption = "Stop Flash"
   Command3.Caption = "Begin Flash"
   Command4.Caption = "Begin Flash"
   
   Check1.Caption = "Window"
   Check2.Caption = "Tray"
   
   Check1.Value = vbChecked
   Check2.Value = vbChecked

End Sub


Private Sub Check1_Click()

   FLASHW_FLAGS = 0&
   If Check1.Value = vbChecked Then FLASHW_FLAGS = FLASHW_CAPTION
   If Check2.Value = vbChecked Then FLASHW_FLAGS = FLASHW_FLAGS Or FLASHW_TRAY
   
End Sub


Private Sub Check2_Click()

   FLASHW_FLAGS = 0&
   If Check1.Value = vbChecked Then FLASHW_FLAGS = FLASHW_CAPTION
   If Check2.Value = vbChecked Then FLASHW_FLAGS = FLASHW_FLAGS Or FLASHW_TRAY
   
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 Command3_Click()

   Call FlashBeginCount(Me.hwnd, _
                        Val(Combo1.List(Combo1.ListIndex)), _
                        Val(Combo2.List(Combo2.ListIndex)))

End Sub


Private Sub Command4_Click()

   Me.WindowState = vbMinimized

   Call FlashBeginUntilActive(Me.hwnd, _
                              Val(Combo1.List(Combo1.ListIndex)), _
                              Val(Combo3.List(Combo3.ListIndex)))
                              
End Sub


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

   Dim fwi As FLASHWINFO
   
   With fwi
      .cbSize = Len(fwi)
      .hwnd = hwnd
      .dwFlags = FLASHW_FLAGS Or FLASHW_TIMER
      .dwTimeout = Frequency
      .uCount = -1
   End With
   
   Call FlashWindowEx(fwi)

End Sub


Private Sub FlashBeginCount(ByVal hwnd As Long, _
                            ByVal Frequency As Long, _
                            ByVal nCount As Long)

   Dim fwi As FLASHWINFO
   
   If (nCount > 0) Then
   
      With fwi
         .cbSize = Len(fwi)
         .hwnd = hwnd
         .dwFlags = FLASHW_FLAGS
         .dwTimeout = Frequency
         .uCount = nCount
      End With
      
      Call FlashWindowEx(fwi)
      
   End If

End Sub


Private Sub FlashBeginUntilActive(ByVal hwnd As Long, _
                                  ByVal Frequency As Long, _
                                  ByVal nCount As Long)

   Dim fwi As FLASHWINFO

   If (Frequency > 0) Then
      
         With fwi
            .cbSize = Len(fwi)
            .hwnd = hwnd
            .dwFlags = FLASHW_TIMERNOFG Or FLASHW_FLAGS
            .dwTimeout = Frequency
            .uCount = nCount
         End With
         
         Call FlashWindowEx(fwi)
      
      
   End If

End Sub


Private Sub FlashEnd(ByVal hwnd As Long)

   Dim fwi As FLASHWINFO
   
   With fwi
      .cbSize = Len(fwi)
      .dwFlags = FLASHW_STOP
      .hwnd = Me.hwnd
      .uCount = 0
   End With
   
   Call FlashWindowEx(fwi)
         
End Sub
 Comments

 
 

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