以下代码显示了关闭窗口的一般方法。此示例适用于 Internet Explorer;您必须针对 Windows Explorer 进行一些调整。
program Sample;
function CloseIEs(Wnd : HWnd; Form : TForm1) : Boolean; export; stdcall;
var
sCap : array [0..255] of char;
begin
GetWindowText (Wnd, sCap, sizeof(sCap));
if pos ('Microsoft Internet Explorer', sCap) > 0 then
begin
PostMessage (Wnd, WM_CLOSE, 0, 0);
end
else
begin
// check by class name!
GetClassName (Wnd, sCap, sizeof(sCap));
if sCap = 'IEFrame' then
PostMessage (Wnd, WM_CLOSE, 0, 0);
end;
CloseIEs := true; { next window, please }
end;
begin
// close all hidden instances
EnumWindows(@CloseIEs, 0);
end.