There is a program that quietly hangs in the background, without windows, only with an icon (sometimes several, through Shell_NotifyIcon created-killed) in the tray.

But when restarting the explorer (well, for example, what kind of failure), these icons are not restored.

Tell me how to correctly organize when restarting the explorer, restarting :) their tray icons?

    1 answer 1

    Subscribe to the TaskbarCreated event. It is called every time you create the “Start Menu” bundle - Quick Launch Panel - Task Bar - Notification Panel ”; from it we are only interested in the last item.

    1. Declare somewhere a global variable to store the identifier of the window message corresponding to the name "TaskbarCreated" :

       static UINT _uTaskbarRestartMessage; 
    2. Somewhere during the initialization of the application, you must perform the actual subscription:

       _uTaskbarRestartMessage = RegisterWindowMessage(TEXT("TaskbarCreated")); 
    3. When we receive a window message with uMsg equal to the _uTaskbarRestartMessage value, we need to recreate all the necessary icons of our application as we did it the first time when the application was started:

       LRESULT CALLBACK WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { switch(uMsg) { // ... default: if(uMsg == _uTaskbarRestartMessage) { // Создаём иконки в панели уведомлений return 0; } else return DefWndProc(hwnd, uMsg, wParam, lParam); } } 
    • Do not you need to delete old ones? Any leaks will not be? - Harry
    • @Harry, no, you do n’t need to delete anything: ... it’s added. - ߊߚߤߘ