How to restore a “missing” notification icon when explorer.exe is restarted?

一个人想着一个人 提交于 2020-03-13 06:44:06

问题


I have a Win32 application which adds a taskbar icon on startup.

It is working perfectly, except when Explorer crashes and then restarts, my application keeps on running, but the taskbar icon is gone.

I suspect I'm supposed to handle some event, but which?


回答1:


What you are referring to are in fact known as notification icons. It's important to get this terminology right so that we know what you mean. Anyway, I think my guess is accurate.

You need to listen for a window message that is broadcast to all top-level windows when the taskbar is created. This is documented like so:

With Microsoft 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 launches. 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);
}


来源:https://stackoverflow.com/questions/32044732/how-to-restore-a-missing-notification-icon-when-explorer-exe-is-restarted

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!