Forms

Flashing title bars

You will have noticed that sometimes, applications flash their title bars to get your attention! Well, you can do this with your program, using the FlashWindow API call. First of all, declare the API call:

Private Declare Function FlashWindow Lib "user32" (ByVal hwnd As Long, ByVal bInvert As Long) As Long

Then, you call it like this:

FlashWindow hWnd, 0

where hWnd is the hWnd property of the window you want to flash. You will notice, however, that this doesn't seem to do anything. This is because when you call the function like this, it simply activates the title bar - and if the title bar is already activated, nothing will happen. If you pass 1 as the second parameter, the title bar will flash:

FlashWindow hWnd, 1

If you want the title bar to flash more than once, the simplest way to do this is to use a timer. You could use something like the code below:

Private Sub tmrFlash_Timer()
FlashWindow hWnd, 1
End Sub

For this to work, you need a Timer control on the form, called tmrFlash. When you want the title bar to start flashing, set tmrFlash.Enabled = True. When you want it to stop, set tmrFlash.Enabled = False. You will also need to decide on the Interval (by setting the Interval property of the Timer) between the flash. I find 500 works quite well.

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Computer Science is no more about computers than astronomy is about telescopes.” - E. W. Dijkstra