Can you send a signal to Windows Explorer to make it refresh the systray icons?

前端 未结 8 757
执笔经年
执笔经年 2020-12-03 00:22

This problem has been afflicting me for quite a while and it\'s been really annoying.

Every time I login after a reboot/power cycle the explorer takes some time to s

相关标签:
8条回答
  • 2020-12-03 00:50

    Take a look at this blog entry: REFRESHING THE TASKBAR NOTIFICATION AREA. I am using this code to refresh the system tray to get rid of orphaned icons and it works perfectly. The blog entry is very informative and gives a great explanation of the steps the author performed to discover his solution.

    #define FW(x,y) FindWindowEx(x, NULL, y, L"")
    
    void RefreshTaskbarNotificationArea()
    {
        HWND hNotificationArea;
        RECT r;
    
        GetClientRect(
            hNotificationArea = FindWindowEx(
                FW(FW(FW(NULL, L"Shell_TrayWnd"), L"TrayNotifyWnd"), L"SysPager"),
                NULL,
                L"ToolbarWindow32",
                // L"Notification Area"), // Windows XP
                L"User Promoted Notification Area"), // Windows 7 and up
            &r);
    
        for (LONG x = 0; x < r.right; x += 5)
            for (LONG y = 0; y < r.bottom; y += 5)
                SendMessage(
                    hNotificationArea,
                    WM_MOUSEMOVE,
                    0,
                    (y << 16) + x);
    }
    
    0 讨论(0)
  • 2020-12-03 00:52

    Include following code with yours to refresh System Tray.

    public const int WM_PAINT = 0xF;
    [DllImport("USER32.DLL")]
    public static extern int SendMessage(IntPtr hwnd, int msg, int character,
                                         IntPtr lpsText);
    
    Send WM_PAINT Message to paint System Tray which will refresh it.
    SendMessage(traynotifywnd, WM_PAINT, 0, IntPtr.Zero);
    
    0 讨论(0)
提交回复
热议问题