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

Raymond Chen

Raymond

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.

Raymond Chen
Raymond Chen

Follow Raymond   

0 comments

Comments are closed.