如何自动移去系统托盘失效的图标

王朝other·作者佚名  2008-06-01
窄屏简体版  字體: |||超大  

有些Window应用程序在启动以后会在系统托盘去添加一个小图标, 一般情况下当程序正常退出时会自动去掉,但有时由于应用程序非法关闭,这个图标便一直留在托盘区,直到用鼠标移动图标上时,才会自己消失.那么我们就可以模拟鼠标移动到逐个图标上,来达到这个效果.

void __fastcall RemoveDeadIcons()

{

HWND hTrayWindow;

RECT rctTrayIcon;

int nIconWidth;

int nIconHeight;

TPoint CursorPos;

int nRow;

int nCol;

// Get tray window handle and bounding rectangle

hTrayWindow = FindWindowEx(FindWindow(

"Shell_TrayWnd", NULL), 0, "TrayNotifyWnd", NULL);

if(!GetWindowRect(hTrayWindow, &rctTrayIcon))

return;

// Get small icon metrics

nIconWidth = GetSystemMetrics(SM_CXSMICON);

nIconHeight = GetSystemMetrics(SM_CYSMICON);

// Save current mouse position }

GetCursorPos(&CursorPos);

// Sweep the mouse cursor over each icon in the tray in both dimensions

for(nRow=0; nRow<(rctTrayIcon.bottom-rctTrayIcon.top)/nIconHeight; nRow++)

{

for(nCol=0; nCol<(rctTrayIcon.right-rctTrayIcon.left)/nIconWidth; nCol++)

{

SetCursorPos(rctTrayIcon.left + nCol * nIconWidth + 5,

rctTrayIcon.top + nRow * nIconHeight + 5);

Sleep(0);

}

}

// Restore mouse position

SetCursorPos(CursorPos.x, CursorPos.x);

// Redraw tray window (to fix bug in multi-line tray area)

RedrawWindow(hTrayWindow, NULL, 0, RDW_INVALIDATE RDW_ERASE RDW_UPDATENOW);

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航