Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 49,032 times

Contents

Related Categories

Forms - Flashing title bars

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.

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • End a sub in another form

    Posted by Bomb3rman on 02 Jul 2005

    In my program I have two forms. The user is asked to input a number in my custom-made form (input box) which has "OK", "CANCEL" and the input textbox.

    Basically the problem is if if the user press...

  • Posted by jawsper on 17 Feb 2005

    true, i noticed that my tray icon doesnt disappear automatically, cause the unload method of the form its on isnt loaded...

    ah well it works fine if you need to really [i]kill[/i] it i guess ;)

  • Posted by James Crowley on 17 Feb 2005

    You don't really want to use End, as it forcefully terminates everything, rather than gracefully telling the forms that they're about to be closed (ie the Unload event), and then removing them from me...

  • Posted by jawsper on 17 Feb 2005

    i know an even simpler method:

    [code]
    Public Sub CloseAll()
    End
    End Sub
    [/code]

    it works fine for me ;)

  • Your answer pointed me to mine!

    Posted by Knoj on 31 May 2003

    If you replace "vbModeless" with "vbModal" then no window below can be clicked on! Great for setting options.