December 13th, 2018

How can I programmatically wait until the taskbar has finished booting completely before I create my notification icon?

A customer found that sometimes their program starts up too soon, and when it tried to create its taskbar notification icon, the call to Shell_Notify­Icon fails. The customer wanted to know whether there was a signal they could listen for to tell them that the taskbar has finished booting completely and is ready to accept notification icons. They noticed that the system puts up an hourglass cursor, and they wondered if perhaps there was a way to monitor the system cursor and wait for it to change to something other than an hourglass.

You can listen for the Taskbar­Created message, which the taskbar sends when the taskbar has been created. Upon receipt of that message, you can try to create your icon again.

The customer asked, “Okay, that’s great. But sometimes our program runs after the taskbar has been created. How can I tell whether the taskbar has been created, so I know that I shouldn’t sit around and wait for the Taskbar­Created message?”

If the taskbar has already been created, then your call to Shell_Notify­Icon will succeed (assuming you didn’t mess up and pass invalid parameters), at which point you don’t need to wait for the Taskbar­Created message because you already created your notification icon.

Monitoring the system cursor is the wrong approach because the system cursor can be an hourglass for other reasons, and it can be an arrow even though the taskbar isn’t ready.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.