unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, ExtCtrls, StdCtrls,registry;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Timer1: TTimer;<br> procedure FormCreate(Sender: TObject);<br> procedure Timer1Timer(Sender: TObject);<br> procedure Button1Click(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br> ieclassname:string;<br> deskwidth,deskheight:integer;<br> //strs:tstrings;<br>implementation<br><br>{$R *.dfm}<br>function enumchildprocs(wnd:hwnd;lparam:lparam):boolean;stdcall;<br>var<br>buffer1:array[0..255] of char;<br>begin<br>result:=true;<br>getclassname(wnd,buffer1,255);<br>//strs.Add(buffer1);<br>end;<br> function getiever(key:string):string;<br> var<br> reg:tregistry;<br> begin<br> reg:=tregistry.Create ;<br> reg.RootKey:=HKEY_LOCAL_MACHINE;<br> if reg.OpenKey('software/microsoft/internet explorer',false) then<br> begin<br> try<br> result:=reg.ReadString(key);<br> except<br> result:='';<br> end;<br> end<br> else<br> reg.Free;<br> end;<br>procedure TForm1.FormCreate(Sender: TObject);<br>var<br>h:thandle;<br>t:trect;<br>begin<br>timer1.Interval :=1000;<br>timer1.Enabled :=false;<br>//if getiever('version')[1]='5' then<br>//ieclassname:='CabinetWclass';<br>//if getiever('version')[1]='5' then<br>//ieclassname:='IEFrame';<br>//if getiever('version')[1]='6' then<br>ieclassname:='IEFrame';<br>h:=findwindow('progman',nil);<br>getwindowrect(h,t);<br>deskwidth:=t.Right-t.Left;<br>deskheight:=t.Bottom-t.Top;<br>//strs:=tstringlist.Create; <br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br>iehandle,iehandle1,ie:thandle;<br>style:longint;<br>ierect:trect;<br>closeie:boolean;<br>i,c,h:integer;<br>ietext:array[0..255] of char;<br>begin<br>c:=0;<br>iehandle:=findwindow(pchar(ieclassname),nil);<br>//iehandle1:=findwindow('IEFrame',nil);<br>//strs.Clear;<br>//enumchildwindows(iehandle,@enumchildprocs,0);<br>{for i:=0 to strs.Count-1 do<br>begin<br>if strs='ReBarWindow32' then<br>begin<br>c:=1;<br>end;<br>end;<br>if c=0 then<br>begin<br>postmessage(iehandle,wm_syscommand,sc_close,0);<br>end;}<br>{iehandle1:=ChildWindowFromPointEx(iehandle,point(50,100),CWP_SKIPINVISIBLE);<br>ie:=FindWindowEx(iehandle,0,nil,'地址(&D)');<br>if ie=0 then<br>begin<br>postmessage(iehandle,wm_syscommand,sc_close,0);<br>end;}<br>if iehandle<>0 then<br>begin<br>closeie:=false;<br>style:=getwindowlong(iehandle,gwl_style);<br>getwindowrect(iehandle,ierect);<br>if ((style and ws_sizebox)<>ws_sizebox) then<br>closeie:=true<br>else<br>with ierect do<br>begin<br>if (right-left>160) and (right-left<500) and (bottom-top>37) and (bottom-top<400) then<br>closeie:=true;<br>end;<br>if ((ierect.right-ierect.left)>(deskwidth+10)) or ((ierect.Bottom-ierect.Top)>(deskheight+10)) then<br>closeie:=true;<br>if ((ierect.right-ierect.left)<(deskwidth-10)) and ((ierect.right-ierect.left)>(deskwidth div 2)) and ((ierect.Bottom-ierect.Top)<(deskheight div 2 +30)) then<br>closeie:=true;<br>h:=getwindowtext(iehandle,ietext,256);<br>if (pos('脱机时无法使用',trim(ietext))>0) or (pos('about:blank',ietext)>0) or (pos('无法连接',ietext)>0) or (pos('找不到服务器',ietext)>0) then<br>closeie:=true;<br>end;<br>if closeie=true then<br>postmessage(iehandle,wm_syscommand,sc_close,0);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>timer1.Enabled :=true;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>timer1.Enabled :=false;<br>end;<br>end.<br>