清理系统托盘中不存在的进程的 NotifyIcons
Clean up NotifyIcons of non-existent processes in system tray
有很多 NotifyIcon 属于已终止的进程。
(到目前为止,我已经看到多达 24 个这样的图标。)
如果用户将鼠标光标移到这些图标上,它们就会消失。
如何以编程方式清理所有 "dead" NotifyIcons?
编辑 1:
一些深入的谷歌搜索表明可以枚举 NotifyIcons 的 HWND。
进一步的工作是微不足道的。稍后会尝试。
How do I programmatically clean up all "dead" NotifyIcons?
你不能。没有 API 这个。我想您可以编写脚本将鼠标光标移动到屏幕的这一部分,但这几乎是您能做的最好的事情。
这是 Windows 7 的有效解决方案。
对于其他版本,window 类 和名称可能不同。
使用 spyxx.exe 工具检查 windows.
的树
HWND Get_Notification_Area_1()
{
HWND hWnd = ::FindWindowA("Shell_TrayWnd", NULL);
if (hWnd)
hWnd = ::FindWindowExA(hWnd, NULL, "TrayNotifyWnd", NULL);
if (hWnd)
hWnd = ::FindWindowExA(hWnd, NULL, "SysPager", NULL);
if (hWnd)
hWnd = ::FindWindowExA(hWnd, NULL, "ToolbarWindow32", "User Promoted Notification Area");
return hWnd;
}
HWND Get_Notification_Area_2()
{
HWND hWnd = ::FindWindowA("NotifyIconOverflowWindow", NULL);
if (hWnd)
hWnd = ::FindWindowExA(hWnd, NULL, "ToolbarWindow32", "Overflow Notification Area");
return hWnd;
}
void Process_Notification_Area(HWND hWnd)
{
if(!hWnd)
return;
RECT rcClient;
BOOL bRet = ::GetClientRect(hWnd, &rcClient);
if(!bRet)
return;
for(int y = rcClient.bottom - 16; y >= 0; y -= 16)
for(int x = rcClient.right - 16; x >= 0; x -= 16)
::PostMessageA(hWnd, WM_MOUSEMOVE, NULL, MAKELPARAM(x, y));
}
void Clean_Up_Notification_Area()
{
Process_Notification_Area( Get_Notification_Area_1() );
Process_Notification_Area( Get_Notification_Area_2() );
}
有很多 NotifyIcon 属于已终止的进程。 (到目前为止,我已经看到多达 24 个这样的图标。) 如果用户将鼠标光标移到这些图标上,它们就会消失。
如何以编程方式清理所有 "dead" NotifyIcons?
编辑 1:
一些深入的谷歌搜索表明可以枚举 NotifyIcons 的 HWND。
进一步的工作是微不足道的。稍后会尝试。
How do I programmatically clean up all "dead" NotifyIcons?
你不能。没有 API 这个。我想您可以编写脚本将鼠标光标移动到屏幕的这一部分,但这几乎是您能做的最好的事情。
这是 Windows 7 的有效解决方案。 对于其他版本,window 类 和名称可能不同。 使用 spyxx.exe 工具检查 windows.
的树 HWND Get_Notification_Area_1()
{
HWND hWnd = ::FindWindowA("Shell_TrayWnd", NULL);
if (hWnd)
hWnd = ::FindWindowExA(hWnd, NULL, "TrayNotifyWnd", NULL);
if (hWnd)
hWnd = ::FindWindowExA(hWnd, NULL, "SysPager", NULL);
if (hWnd)
hWnd = ::FindWindowExA(hWnd, NULL, "ToolbarWindow32", "User Promoted Notification Area");
return hWnd;
}
HWND Get_Notification_Area_2()
{
HWND hWnd = ::FindWindowA("NotifyIconOverflowWindow", NULL);
if (hWnd)
hWnd = ::FindWindowExA(hWnd, NULL, "ToolbarWindow32", "Overflow Notification Area");
return hWnd;
}
void Process_Notification_Area(HWND hWnd)
{
if(!hWnd)
return;
RECT rcClient;
BOOL bRet = ::GetClientRect(hWnd, &rcClient);
if(!bRet)
return;
for(int y = rcClient.bottom - 16; y >= 0; y -= 16)
for(int x = rcClient.right - 16; x >= 0; x -= 16)
::PostMessageA(hWnd, WM_MOUSEMOVE, NULL, MAKELPARAM(x, y));
}
void Clean_Up_Notification_Area()
{
Process_Notification_Area( Get_Notification_Area_1() );
Process_Notification_Area( Get_Notification_Area_2() );
}