C++刷新托盤程序圖標
托盤程序在非正常被關閉的情況下,就會出現托盤圖標不消失的情況,需要鼠標移到上面纔會消失。這裏就模擬鼠標事件來處理。但是對於縮到托盤裏面的圖標則沒有辦法刷新,待找...
#include <windows.h>
#include <iostream>
int main() {
HWND shell_tray_wnd_handle = FindWindow(L"Shell_TrayWnd", NULL);
HWND tray_notify_wnd_handle = FindWindowEx(shell_tray_wnd_handle, 0, L"TrayNotifyWnd", NULL);
HWND sys_paper_handle = FindWindowEx(tray_notify_wnd_handle, 0, L"SysPager", NULL);
HWND tool_bar_handle = NULL;
if (sys_paper_handle != NULL) {
tool_bar_handle = FindWindowEx(sys_paper_handle, 0, L"ToolbarWindow32", NULL);
}
else {
tool_bar_handle = FindWindowEx(tray_notify_wnd_handle, 0, L"ToolbarWindow32", NULL);
}
if (tool_bar_handle == NULL) {
return 0;
}
RECT rect;
GetWindowRect(tool_bar_handle, &rect);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
for (int x = 1; x < width; x += 2) {
for (int y = 1; y < height; y += 2) {
SendMessage(tool_bar_handle, WM_MOUSEMOVE, 0, MAKELPARAM(x, y));
}
}
return 0;
}