How do I flash my window caption and taskbar button manually?


Commenter Jonathan Scheepers wonders about those programs that flash their taskbar button indefinitely, overriding the default flash count set by SysteParametersInfo(SPI_SETFOREGROUNDFLASHCOUNT).

The FlashWindowEx function and its simpler precursor FlashWindow let a program flash its window caption and taskbar button manually. The window manager flashes the caption automatically (and Explorer follows the caption by flashing the taskbar button) if a program calls SetForegroundWindow when it doesn't have permission to take foreground, and it is that automatic flashing that the SPI_SETFOREGROUNDFLASHCOUNT setting controls.

For illustration purposes, I'll demonstrate flashing the caption manually. This is generally speaking not recommended, but since you asked, I'll show you how. And then promise you won't do it.

Start with the scratch program and make this simple change:

void
OnSize(HWND hwnd, UINT state, int cx, int cy)
{
  if (state == SIZE_MINIMIZED) {
    FLASHWINFO fwi = { sizeof(fwi), hwnd,
                       FLASHW_TIMERNOFG | FLASHW_ALL };
    FlashWindowEx(&fwi);
  }
}

Compile and run this program, then minimize it. When you do, its taskbar button flashes indefinitely until you click on it. The program responds to being minimzed by calling the FlashWindowEx function asking for everything possible (currently the caption and taskbar button) to be flashed until the window comes to the foreground.

Other members of the FLASHWINFO structure let you customize the flashing behavior further, such as controlling the flash frequency and the number of flashes. and if you really want to take control, you can use FLASHW_ALL and FLASHW_STOP to turn your caption and taskbar button on and off exactly the way you want it. (Who knows, maybe you want to send a message in Morse code.)

Comments (19)
  1. John says:

    <i>And then promise you won’t do it.</i>

    You are adorable.

  2. Adrian says:

    Please don’t do this.

    Many of us hide the Task Bar except when we’re using it.  When you’re Task Bar button is flashing, it forces the Task Bar up, over the bottoms of our maximized windows, forcing us to task switch twice just to stop the blinkin’ blinkin’!

    Indefinite flashing is almost as bad as utterly useless Task Bar notification area balloons.

  3. MS says:

    An interesting anecdote about the "Morse Code" idea: back in the day, someone actually rigged up a program that would flash the keyboard status lights so that an external camera system could record whatever the message was as a sort of vector for sending sensitive data out.  Using the taskbar flashing for this could theoretically be done, but a screensaver would of course be an issue.

  4. Nidonocu says:

    I hope this eventually is something Microsoft eventually ‘locks down’ as it does with other abused system features. Currently Live Messenger for example flashes about 21 times! Then stays lit. On the other hand, Trillian (the multi-medium IM client) by default I believe flashes just three times and then stays lit, which is a lot less annoying.

    As mentioned previously here, providing a user configurable feature beyond maybe the registry and tweak tools is a bit too much, but capping the flashes at 10 would be far more reasonable.

    Is there any real reason an app should be allowed to flash forever when staying lit is perfectly fine?

  5. Marc says:

    Eric –

    Windows Live Messenger breaks every best practice in the book. Try dragging the window to the top of the screen when the menu is hidden – you can’t because the menu is still there, although invisible  (in Windows Vista, the TaskBar live preview also shows an empty area above the Window where there would be a menu.

    Add to all that the fact that they don’t use standard UI widgets, when a connection fails there is no retry button, the system tray icon remains under vista when you exit it, and for some reason if Internet Explorer is set to "Offline" mode – it can’t connect, and it doesn’t offer a "go online" button – rather it tells you to open up IE and do it yourself. Quite lazy,  I can understand why it needs IE to be online (to show adverts) – but why not have a "connect.." button like IE does? It doesn’t use my default browser to open Hotmail.. the lost goes on :)

    So I guess Windows Live is where Microsoft train their developers up before moving them onto important stuff?

  6. Marc says:

    I guess this is the lesser of many evils. On Mac OS X I remember icons used to bounce (we’re going back to 10.0 – 10.3 I think here) – the bouncing would keep going under the app said so, and it would consume huge amounts of my poor little CPU animating this fancy transparent icon.AOL used to be a big offender here. really bad if you were in a game.

  7. Dan says:

    Eric, that happens to me with the Trillian Astra alpha on XP.  I had assumed that was a Trillian bug but maybe not.

  8. Pas B says:

    Lotus Sametime also flashes an updated chat/IM window’s button indefinitely.  I agree with Adrian and others:  In addition to the distraction of the flashing itself, the fact that this forces display of the taskbar is extremely bothersome.  In my work environment, one will often be multitasking several/many low-throughput chat/IM’s.  I’d like maybe a flash or three as notification, and then persistent highlighting of the button as a reminder, when a new message shows up but I’ve not yet activated that window.  However, anything more gets in my way.  I wish I had a way to, as the user, impose my will upon and override this UI abuse.

  9. Erik says:

    Why shouldn’t we use manual flashing at all? How does the windows-user control if SetForegroundWindow() is allowed to foreground or not? Flashing the task-bar is IMO a nice way of telling the user that an event has occurred without just taking focus, which can possibly be destructive in some cases (user wrongly typing a letter into the wrong window or causing a d3d lost device ?). I would love to get some better explanation on this.

  10. Neil says:

    FlashWindowEx looks like a much-needed improvement over FlashWindow although the documentation is unclear as to what you should do if you want to flash one of your other windows because it has opened a dialog (the top-level window itself will never become the foreground window until you end the dialog.)

  11. Eric Bickle says:

    What I’m curious about are the applications that have "phantom taskbar flashes".

    For example, in Windows Live Messenger I might see a message arrive in a chat window. I minimize the window, only to have it flash about a new message.

    Click the task bar, restore the chat window – and sure enough – no new chat messages. Minimize it again, flashing goes away.

    It’s gotten so bad that I basically have to minimize chat windows *twice* every time I get a new message. The strange thing is, I’ve seen this behavior from other applications as well.

    Common application bug, or API issue?

  12. Cooney says:

    Flashing the task-bar is IMO a nice way of telling the user that an event has occurred without just taking focus, which can possibly be destructive in some cases (user wrongly typing a letter into the wrong window or causing a d3d lost device ?).

    What I really want is a way to override apps that do this – a UI that doesn’t allow for this sort of pimpslap is broken. It is, after all, my desktop, and I decide what’s important.

    Also, stealing UI should be something I can disable.

  13. Harley says:

    I have to say, I’d rather have an application flash at me to tell me it’s done doing something rather than blare sounds over my speakers (or beep from the system speaker), which could be too loud/too quiet/out of earshot, or bring up a message box, which would think it’s king of the world.

    Cooney:

    Also, stealing UI should be something I can disable.

    Get TweakUI.  Under General > Focus, you can tell it to stop applications from taking focus and flash so many times (or until you give it focus).

    I think some applications attempt to break that setting at certain points, but more or less it does keep windows from stealing focus.

    It’s a lifesaver when trying to do anything else while running a process that uses another  application that tries to steal focus on every little thing it does.

    Eric and Dan:

    I might see a message arrive in a chat window. I minimize the window, only to have it flash about a new message.

    Click the task bar, restore the chat window – and sure enough – no new chat messages. Minimize it again, flashing goes away.

    I have this occur using Trillian (3.1) as well, so who knows where the issue occurs.

  14. Worf says:

    What I hate about this are the apps that flash, but you’re not in front of the computer, and you miss it.

    The good apps have a highlighted taskbar button, which tells you which apps "went off". But others look normal, and if you have a hiding taskbar…`it stops hiding until you find the offending window and bring it forward. At which point the taskbar hides again. Frustration playing whack-a-mole to find that one app…

    The one good thing – most web browsers have no link between this API and their scripting engine. Last thing you want is to have a billion web browser windows and tabs blinking at you.

  15. A says:

    So… how do I turn this off?

    Flashing is just about the most annoying possible thing on a computer screen. Annoying the user is something that no software should ever do. Software exists solely to serve the user, annoying the user is the antithesis of service.

    Can’t we just have it so that any application that attempts to flash just gets their button highlighted? Much less annoying, but preserves some functionality.

  16. Keep the flash says:

    > Software exists solely to serve the user, annoying the user is the antithesis of service.

    Wrong generalization. In many situations, the user (operator technically) is there to serve the software, the exact opposite. Not every software is shrinkwrap for your desktop.

    And many of the things many ask to be disabled (power management refusal, taskbar flashing, etc.) are actually very useful in those scenarios where the user is just a stage of a complex system (often not even the most important one).

  17. A says:

    Wrong generalization. In many situations, the user (operator technically) is there to serve the software, the exact opposite. Not every software is shrinkwrap for your desktop.

    The user that the software is serving is not necisarily the one sitting in front of the computer at the time, however I will conceed that there are situations where the person that the software is serving will never have interacted with it directly.

    The point still stands, if a feature does not serve the interests of a human who has a legitimate reason to be served, the feature should not exist.

  18. Triangle says:

    ">> Software exists solely to serve the user, annoying the user is the antithesis of service.

    Wrong generalization. In many situations, the user (operator technically) is there to serve the software, the exact opposite. Not every software is shrinkwrap for your desktop."

    These are two distinct sitations. There is software that exists solely to serve the user, and there is software that must serve itself or be served by the user. There are no legitimate reasons the former should be allowed to blink ad-nauseum and mess up the UI, but there be valid reasons for the latter to do so. You’re arguing apples to orranges here.

Comments are closed.

Skip to main content