top of page

Flashing the taskbar icon and window using the Windows API

  • Writer: John
    John
  • 6 days ago
  • 3 min read
This post is one of a series providing implementation examples of Windows API Functions, Types, Enums and Consts using VBA. The code in this post can be used as-is, however, if you regularly (or even just occasionally) work with Windows API declarations in VBA, you may want to see the posts Automatically add Windows API declaration(s) and Using 'F1' to view Windows API web pages which explain some of the functionality that can be added to the VBE by VBE_Extras.

This post demonstrates how to use the FlashWindow or FlashWindowEx Windows API Functions to flash the taskbar icon and window for an application ... could be the host application (Excel, Word, Access etc) or another application. Why would you want to do this ... I guess to bring attention to that application ... maybe a long-running process has completed and you need the user to notice.


FlashWindow is the more basic of the two Functions. You pass it a window handle and it flashes the window and taskbar icon once (or returns them to their original state).


FlashWindowEx has more options. You pass it a FLASHWINFO Type which includes the window handle and other options controlling the number of flashes (or whether the flashing should be continuous until the application window is brought to the foreground ... typically by the user opening the application), the duration between each flash and what is flashed: either the window, the taskbar icon or both.


The following code demonstrates each of these ... first FlashWindow. The code here has options to flash either the host application window or the Notepad window.


For the host application, if using an application other than Excel, you will need to change Application.hWnd to get the handle for the relevant host ... either see my post Get the application window handle in any app (well ... in Excel, Word, Access, PowerPoint or Outlook) or if using Word use Application.ActiveWindow.hWnd or if using Access use Application.hWndAccessApp.


For the Notepad window, you will need to open Notepad first!


The code also uses the FindWindow Windows API Function to get the handle of the Notepad window (as does the following code for FlashWindowEx).

Run the FlashApplicationWindowOnce and/or FlashNotepadWindowOnce VBA Functions to demonstrate.


Next the code for FlashWindowEx. The code following only has a demonstration VBA Functions to flash the Notepad window but, to flash the window for the host application instead, just replace the call of GetNotepadWindowHandle in each of the demonstration Functions with Application.hWnd for Excel or other code as noted above if using another host application.


The core of the code is in the VBA Function FlashWindowRepeatedly which creates an instance of the FLASHWINFO Type, sets its members appropriately and then passes it in to a call of FlashWindowEx. A key thing to note is that the cbSize member of this Type must be set to the size of the Type in bytes ... to do this, the LenB Function is used.


Run the FlashNotepadWindowRepeatedlyOngoing, FlashNotepadWindowRepeatedlyTenTimes and/or FlashNotepadWindowRepeatedlyTenTimesRapid VBA Functions to demonstrate.


Note that the 'flash' is quite different in Windows 10 vs 11 …

  • Windows 10 is a slow fade in/out and so even 'flash once' actually flashes a few times and flashing rapidly just looks like a mess!

  • Windows 11 is a clear blink on for FlashWindow and on/off for FlashWindowEx and so is much cleaner ... and we're all using Windows 11 now anyway eh?!

bottom of page