现在的位置: 首页 > 综合 > 正文

清理任务栏残留图标Delphi版 附源程序

2014年02月11日 ⁄ 综合 ⁄ 共 998字 ⁄ 字号 评论关闭

 
//我想任何人都遇到过这样的情况:
//任务栏右下角的快捷图标有时并不会随着程序的关闭而消失
//只有当鼠标划过时才消失
//下面的函数可以通过自动划过并清除这些图标

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;

 

(请参考VB6版:清理任务栏残留图标VB6版 附源程序)
http://blog.csdn.net/tanaya/archive/2006/09/20/1253038.aspx

 

 

抱歉!评论已关闭.