Tray icon vanishing

Started by Torkell,

Torkell

I often minimize XMPlay to the tray, to reclaim much needed screen space (e.g. for 2 MSDN library windows and 3 VB windows). However, should explorer (the shell) crash while it is in "tray icon" mode, the icon will be gone for good and the only way to regain control of XMPlay is to kill the process with Task Manager. Now, I *know* it is possible to make the icon survive shell restarts, because my utility that sits in the tray does that. I have checked in the MSDN library, and here is what it says about it:

Taskbar Creation Notification
With Internet Explorer 4.0 and later, the Shell notifies applications that the taskbar has been created. When the taskbar is created, it registers a message with the TaskbarCreated string and then broadcasts this message to all top-level windows. When your taskbar application receives this message, it should assume that any taskbar icons it added have been removed and add them again. This feature generally applies only to services that are already running when the Shell begins execution. The following example shows a very simplified method for handling this case.
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
    static UINT s_uTaskbarRestart;

    switch(uMessage)
    {
        case WM_CREATE:
            s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
            break;
        
        default:
            if(uMessage == s_uTaskbarRestart)
                AddTaskbarIcons();
            break;
    }

    return DefWindowProc(hWnd, uMessage, wParam, lParam);
}

Obviously the workings of XMPlay are more complicated than that but it should show you how to solve that problem. I've noticed quite a few programs (including one or two by Micro$oft) fail to include that short bit of code, and it is annoying when I manage to kill the shell and then find half my tray icons have disappeared!

Torkell

Go here ("The Taskbar") for more information about this (it's near the bottom of the page).