Can I re-gain a systray icon of a running app that has gone missing?

断了今生、忘了曾经 提交于 2019-12-20 10:27:53

问题


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


回答1:


I've written a project that sends a TaskbarCreated message to all of the top-level windows in the system. If they've registered a tray icon, that should cause them to restore the icon after explorer has crashed.

I've released the source under the MIT license, and provided a link to the compiled console application (with Lazarus) in the readme file.

There are certainly a few refinements that could be made, like not sending the message if the icon is known to be in the tray already, but for now this app causes the icons that I know go missing on an Explorer crash to reappear.




回答2:


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).




回答3:


This worked for me (Windows 7 - 64 bit)

  1. Launch taskmanager
  2. Kill apachemonitor process
  3. Launch apachemonitor from Start menu

You should now see the icon in the systray



来源:https://stackoverflow.com/questions/1114887/can-i-re-gain-a-systray-icon-of-a-running-app-that-has-gone-missing

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