procedure RemoveDeadIcons; var TrayWindow : HWnd; WindowRect : TRect; SmallIconWidth : Integer; SmallIconHeight : Integer; CursorPos : TPoint; Row : Integer; Col : Integer; begin { 获得任务栏句柄和边框} if TOSVersion.Major>=6 then //Win7以上 TrayWindow := FindWindowEx(FindWindow('NotifyIconOverflowWindow',NIL),0,'ToolbarWindow32',NIL) else TrayWindow := FindWindowEx(FindWindow('Shell_TrayWnd',NIL),0,'TrayNotifyWnd',NIL); if not GetWindowRect(TrayWindow,WindowRect) then Exit; { 获得小图标大小} SmallIconWidth := GetSystemMetrics(SM_CXSMICON); SmallIconHeight := GetSystemMetrics(SM_CYSMICON); { 保存当前鼠标位置} GetCursorPos(CursorPos); { 使鼠标快速划过每个图标 } with WindowRect do begin for Row := 0 to (Bottom - Top) DIV SmallIconHeight do for Col := 0 to (Right - Left) DIV SmallIconWidth do begin SetCursorPos(Left + Col * SmallIconWidth, Top + Row * SmallIconHeight); Sleep(4); end; end; {恢复鼠标位置} SetCursorPos(CursorPos.X,CursorPos.Y); { 重画任务栏 } RedrawWindow(TrayWindow,NIL,0,RDW_INVALIDATE OR RDW_ERASE OR RDW_UPDATENOW); end;
----------------------------------------------
vvvvvvvvvv
procedure TForm1.RemoveDeadIcons; var TrayWindow : HWnd; WindowRect : TRect; SmallIconWidth : Integer; SmallIconHeight : Integer; CursorPos : TPoint; Row : Integer; Col : Integer; begin { 获得任务栏句柄和边框} TrayWindow := FindWindowEx(FindWindow('Shell_TrayWnd',NIL),0,'TrayNotifyWnd',NIL); if not GetWindowRect(TrayWindow,WindowRect) then Exit; { 获得小图标大小} SmallIconWidth := GetSystemMetrics(SM_CXSMICON); SmallIconHeight := GetSystemMetrics(SM_CYSMICON); { 保存当前鼠标位置} GetCursorPos(CursorPos); { 使鼠标快速划过每个图标 } with WindowRect do begin for Row := 0 to (Bottom - Top) DIV SmallIconHeight do begin for Col := 0 to (Right - Left) DIV SmallIconWidth do begin SetCursorPos(Left + Col * SmallIconWidth, Top + Row * SmallIconHeight); Sleep(10); //发现这个地方参数为 0 的时候,有时候是不够的 end; end; end; {恢复鼠标位置} SetCursorPos(CursorPos.X,CursorPos.Y); { 重画任务栏 } RedrawWindow(TrayWindow,NIL,0,RDW_INVALIDATE OR RDW_ERASE OR RDW_UPDATENOW); end;
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.