首先添加一个Timer控件,创建一个过程 private { Private declarations } procedure KillChildWindows(hand: HWND); 代码如下: procedure TForm1.KillChildWindows(hand: HWND); var h: HWND; s: Array[0..255] of char; IsPopWindow: Bool; begin IsPopWindow:=True; h:=GetWindow(hand,GW_child); while h>0 do begin GetClassName(h, s, 256); if (StrPas(s)='WorkerA') or (StrPas(s)='WorkerW') then If IsWindowVisible(h) then IsPopWindow:=False; h:=GetWindow(h,GW_HWNDNEXT); end; if IsPopWindow then PostMessage(hand,WM_CLOSE,0,0); end;
procedure TForm1.Timer1Timer(Sender: TObject); var h: HWnd; Text: array [0..255] of char; begin h:=GetWindow(Handle, GW_HWNDFIRST); while h <> 0 do begin if GetWindowText(h, @Text, 255)>0 then if GetClassName(h, @Text, 255)>0 then if (StrPas(Text)='CabinetWClass') or (StrPas(Text)='IEFrame') then KillChildWindows(h); h:=GetWindow(h, GW_HWNDNEXT); end; end;