不以物喜,不以己悲

C++刷新托盘程序图标

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;
}
posted @ 2021-01-20 19:36  这种人  阅读(568)  评论(0编辑  收藏  举报