我想任何人都遇到过这样的情况:任务栏右下角的快捷图标有时并不会随着程序的关闭而消失,只有当鼠标划过时才消失,下面的函数可以通过自动划过并清除这些图标。
procedure 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(0);
end;
end;
end;
{恢复鼠标位置}
SetCursorPos(CursorPos.X,CursorPos.Y);
{ 重画任务栏 }
RedrawWindow(TrayWindow,NIL,0,RDW_INVALIDATE OR RDW_ERASE OR RDW_UPDATENOW);
end;