Instead of creating something and then trying to hide it, simply don’t create it in the first place

A customer had a question, which was sort of I bet somebody got a really nice bonus for that feature in reverse.

A customer is asking if there is a way to programmatically control the icons in the notification area.

Specifically, they want the setting for their notification icon to be "Only show notifications" rather than "Show icon and notifications" or "Hide icon and notifications."

Icons Behaviors
Show icon and notifications
Fully charged (100%)
Show icon and notifications
Fabrikam Internet access
Show icon and notifications
Speakers: 10%
Contoso Resource Notification
Only show notifications
No new resources found.

It's a good thing the customer explained what they wanted, because they started out asking for the impossible part. Arbitrary control of notification icons is not programmatically exposed because all the awesome programs would just force themselves on. But they clarified that what they really want is a way to reduce the visibility of their icon so it displays only when a notification is being shown.

And there's a way to do that, and it doesn't involve having to programmatically configure anything.

If you don't want your notification icon to appear in the notification area, then don't show your notification icon in the first place unless you have a notification.

  • When your program starts, don't call Shell_Notify­Icon(NIM_ADD). Since you don't call the function, you don't get a notification icon.
  • When you want to display a notification, call Shell_Notify­Icon(NIM_ADD).
  • When the situation that calls for the notification has passed, call Shell_Notify­Icon(NIM_REMOVE).

In other words, use the notification icon in the manner it was intended.

It's sad that notification icon abuse has become so popular (and application frameworks make it so easy to create an abusive notification icon) that people forget how to create a well-behaved notification icon. Instead, they start with the abusive method, and then try to figure out how to make it less abusive.

Comments (16)
  1. Joshua says:

    I also see lots of "minimize to tray" or similar ideas where the minimized application shows up as a notification icon, which is really desirable for a program that must be always running to function but doesn't need to real-estate that an application would need. First popularized by anti-virus programs.

  2. Mason Wheeler says:

    Niiiiiiice!  It's always fun to see the way some coders just don't seem to have enough common sense to do it the simple way.

  3. Daniel says:

    I have to agree with Joshua. It's probably not how the notification area was envisioned, but an extremely common use these days is to keep a discrete indication about resident apps, and this is probably what the customer wanted to do.

  4. No One says:

    Wait, what if a program wants the /default/ to be "Only show notifications" instead of "Show icon and notifications" but wants to still allow the user to change that if the user disagrees?  (Assume here that the program doesn't want to force itself to be "Only show notifications" when the user has set the default to "Hide icon and notifications" (assuming you can do that — I don't have my Win7 box in front of me at the moment.))

    Sure, the program could put its /own/ setting in for whether to show up or not, but then, what's the point of centralizing the pretty Win7 support for it?

    [The point wasn't centralization. The point was "giving you a way to clean up garbage thrown on the street" (even though people shouldn't be throwing garbage on the street in the first place). -Raymond]
  5. Joshua says:

    [The point was "giving you a way to clean up garbage thrown on the street" -Raymond]

    Action Center. Sync Center. Fully hiding Action Center is possible but breaks Windows Update notifications. Too bad actually permitting the notification area to show all icons is no longer realistic.

  6. shane says:

    "When the situation that calls for the notification has passed, call Shell_NotifyIcon(NIM_REMOVE)"

    How does the program know when this has happened? Supposedly they want to hide the icon after the notification is dismissed – which you'd think should be handled by the OS which is displaying the notification and handling the dismissal. I still see why they'd want to do it the original way (letting the OS manage the display of the icon). Otherwise they have to try work out when the notification is dismissed (perhaps there is a message?)

    [I'm assuming the notification is based on a condition, like "there is an unread email message" or "your battery is low". -Raymond]
  7. shane says:

    [I'm assuming the notification is based on a condition, like "there is an unread email message"..]

    There are other common notifications like 'Download complete', 'New wireless networks discovered' where the condition persists even after dismissal. It is after-all a "notification", not necessarily a "state". I can certainly see a requirement for a generic means to "notify" without having to do icon management.

  8. AC says:


    Doesn't this fall under your "I can't believe I had to write this" category?

  9. Zian Choy says:

    doesn't need to real-estate that an application would need

    Can't the program just go away completely and pop up with a balloon notification (or whatever's needed) as needed?

  10. ThomasX says:

    Let me rephrase the header:

    Instead of introducing bugs and then going to great length to document and excuse them, simply fix them in the first place.

  11. dave says:

    Is there some way I can hide this comment?

  12. barbie says:

    @dave: Sure, add an entry to the suggestion box that says something along the lines of "Raymond, can you remove comment…/10270776.aspx ?". I'm sure he'll acquiesce. </whoosh>

  13. ErikF says:

    @dave: If you have Fiddler, you could have it rewrite this page so that your comment has the hidden CSS attribute set. That works too!

  14. Ben Voigt [Visual C++ MVP] says:

    This "solution" has very different behavior than what was requested.

    "No one" already mentioned the possibility for the user to configure the notifications.

    But even absent that, the "Show only notifications" causes an icon to appear when the little arrow beside the notification area is clicked to expand hidden icons.  Icons there provide access to nifty things like a popup menu to exit the daemon.  Exiting the daemon allows things like upgrading dependencies (Java, for instance) without a reboot (if the daemon is left running, the files requiring replacement are in use).

    By not creating the icon at all, instead of creating it in the hidden list, there's no UI to access the daemon.

    Now, in Windows 7 the running applications bar is no longer as scarce a resource as it used to be, but having an icon there still uses considerably more screen estate than a notification icon (let alone a hidden notification icon).

    So where do you put an exit menu where the user can get to it when needed, but it doesn't take up screen space otherwise?

    [The guidance for that hasn't changed since 1995. Put it on the Start menu. -Raymond]
  15. Strange, I can't think of any applications which have a Start menu item for quitting a running process. There's a certain comedy value to spawning a new process from a Start menu shortcut just to tell an existing process to quit, but I suppose it could make some sense.

    Creating things only to show them again was actually the culprit in a performance issue I debugged earlier this year: we had an outsourced application to gather weekly data on project progress. In order to display the current week's data, it generated ALL the UI elements for every week of the whole project, then hid all but the current week – so the longer the project duration, the longer it took to load. (This was a web application, rather than desktop.)

    [The shortcut would reopen the main UI, from which the user could close the application. -Raymond]
  16. DWalker says:

    When I am asked to work on someone's computer, due to slowness or other issues, I often set it to show all notification icons.  Then I go through each program and ask the user if they need program XYZ or not, and often their answer is "I don't know what that program does, and I don't use it".  So I uninstall it.

    Showing all icons all the time has the terrific side-effect of reminding people to clean up junk that they don't need.  

    Also, I am surprised that more people don't use a two-row-high taskbar.  You get the added benefit of date and "day of the week" below the clock, along with allowing all notification icons to be shown without taking up so much of the taskbar.

Comments are closed.

Skip to main content