要清空任务栏,您可以使用以下步骤:
获取任务栏窗口句柄
```delphi
var
TrayWindow: HWnd;
begin
TrayWindow := FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0, 'TrayNotifyWnd', nil);
end;
```
遍历任务栏图标并移除
```delphi
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
// 这里可以添加代码来移除每个图标
end;
end;
end;
end;
```
调用 `RemoveDeadIcons` 过程
```delphi
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
RemoveDeadIcons;
end;
```
请注意,这些代码片段可能需要根据您的具体需求进行调整。例如,您可能需要添加额外的逻辑来处理任务栏图标的移除,或者确保在移除图标时不会影响其他系统功能。