var
hTrayWindow: HWND;
rctTrayIcon: TRECT;
nIconWidth,nIconHeight: integer;
CursorPos: TPoint;
nRow,nCol: Integer;
Begin
// 获得任务栏句柄和边框}
// hTrayWindow := FindWindow('Shell_TrayWnd',nil);
hTrayWindow := FindWindowEx(FindWindow('Shell_TrayWnd',nil),0,'TrayNotifyWnd',nil);
if not (GetWindowRect(hTrayWindow, rctTrayIcon)) then
Exit;
// 获得小图标大小
nIconWidth := GetSystemMetrics(SM_CXSMICON);
nIconHeight := GetSystemMetrics(SM_CYSMICON);
// 保存当前鼠标位置
GetCursorPos(CursorPos);
//鼠标快速划过每个图标
for nRow := 0 To ((rctTrayIcon.bottom-rctTrayIcon.top) div (nIconHeight)) Do
Begin
for nCol := 0 To ((rctTrayIcon.right-rctTrayIcon.left) div (nIconWidth)) Do
Begin
SetCursorPos(rctTrayIcon.left + nCol * (nIconWidth )+ 8,
rctTrayIcon.top + nRow * (nIconHeight) + 8);
Sleep(0);
end;
end;
//恢复鼠标位置
SetCursorPos(CursorPos.x, CursorPos.x);
//重画任务栏
RedrawWindow(hTrayWindow, nil, 0, RDW_INVALIDATE Or RDW_ERASE Or RDW_UPDATENOW);
end;