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);
}








