views:

363

answers:

1

Since I've finally got an answer for this question: Can you send a signal to windows explorer to make it refresh the systray icons, that asks about getting rid of dead systray icons, I would like to ask for the opposite.

Is there a way to "nudge" an application to re-show it's systray icon if it has been lost?

It happens to my Apache Monitor ever since I install Avira AV.
Ok, granted, it could only be a side effect, but it's quite annoying to have the running app killed an then restart it, just because it's not displaying the systray icon correctly.

Thanks in advance,
Gus

+6  A: 

Restoring the task bar icon is something that is implemented by the application itself (rather than Explorer). There is a window message called "TaskbarCreated" (its value can be obtained with RegisterWindowMessage("TaskbarCreated")) that an application needs to respond to, in order to restore the task bar icon when necessary.

For example, the application can do this:

const int uTaskbarCreatedMsg = RegisterWindowMessage("TaskbarCreated");

Then in its WndProc function:

LRESULT CALLBACK WndProc(HWND w, UINT msg, WPARAM wparam, LPARAM lparam)
{
    // ... handle other messages
    if (msg == uTaskbarCreatedMsg) {
        NOTIFYICONDATA nid;
        // fill in details to create icon
        Shell_NotifyIcon(NIM_ADD, &nid);
        return 0;
    }
    // ... default message handling
}

So in order to force an application to restore its task bar icon, you will need to send the same TaskbarCreated message to the appropriate window within the application. One way to get the HWND to the window is to use FindMessage (and since Apache Monitor is open source, it's easy to discover which window to look for).

Greg Hewgill
Your solution is from the point of view of the application that has the icon. What I'm looking for is an external way to signal that app to refresh the icon or signal SysTray to refresh it's list of icons.
Gustavo Carreno
Sending that app the TaskbarCreated message might just do the trick. Otherwise, if the Apache Monitor application doesn't support that message, then since it's open source you can add the capability using the above code.
Greg Hewgill
I looked up the source for the Apache Monitor application (here: http://svn.apache.org/viewvc/httpd/httpd/trunk/support/win32/ApacheMonitor.c?view=log#rev90160 ) and it appears as though it has supported the TaskbarCreated message since its first version in 2001. So, if you run into a situation where its icon disappears, then sending that message to Apache Monitor should tell it to recreate its icon in Explorer.
Greg Hewgill
Thanks Greg for the thorough investigation. I'll have a play with sending those messages and see if it works. Could you re-phrase your answer so it shows this new solution? This way I can mark it the chosen answer. Thanks!!
Gustavo Carreno