重金(300)求解:如何在程序中关闭IE?? (300分)

  • 主题发起人 主题发起人 amengdewo
  • 开始时间 开始时间
A

amengdewo

Unregistered / Unconfirmed
GUEST, unregistred user!
已试过的方法: <br>先找到IE的Handle(已找到), <br>SendMessage(hWindow, WM_CLOSE, 0, 0); //但IE并没有关掉 <br><br>这个方法可以关闭记事本、计算器等程序。 <br><br>我的邮箱ameng@ameng.com<br><br><br><br><br>
 
procedure TForm1.Button1Click(Sender: TObject);<br>var iehandle:Thandle;<br>begin<br>iehandle:=findwindow('ieframe',nil);<br>postmessage(iehandle,WM_close,0,0);<br>end;<br><br>
 
我有一个案例,你可以参考一下,给个邮箱
 
应该有简单方法!
 
var<br>&nbsp; ShellWindow: IShellWindows;<br>&nbsp; nCount: integer;<br>&nbsp; spDisp: IDispatch;<br>&nbsp; i,j: integer;<br>&nbsp; vi: OleVariant;<br>&nbsp; IE1: IWebBrowser2;<br>&nbsp; IDoc1: IHTMLDocument2;<br>begin<br>&nbsp; ShellWindow := CoShellWindows.Create;<br>&nbsp; nCount := ShellWindow.Count;<br><br>&nbsp; for i := 0 to nCount - 1 do<br>&nbsp; begin<br>&nbsp; &nbsp; vi := i;<br>&nbsp; &nbsp; spDisp := ShellWindow.Item(vi);<br>&nbsp; &nbsp; if spDisp = nil then continue;<br>&nbsp; &nbsp; spDisp.QueryInterface( iWebBrowser2, IE1 );<br>&nbsp; &nbsp; if IE1 &lt;&gt; nil then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; IE1.Document.QueryInterface(IHTMLDocument2,iDoc1);<br>&nbsp; &nbsp; &nbsp; if iDoc1 &lt;&gt; nil then<br>&nbsp; &nbsp; &nbsp; &nbsp; ie1.Quit<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br><br>或者 &nbsp; &nbsp;if IE1 &lt;&gt; nil then ie1.quit ,但可能会把资源管理器的窗口也关了<br>
 
一切与IE有关的窗口死光光<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; i:integer;<br>&nbsp; hWndStart,hwndLike:HWND;<br>&nbsp; WndCaption:array[0..254] of char;<br>&nbsp; WndClassName:array[0..254] of char;<br>&nbsp; WindowCaption,WindowClass: array [1..12] of string;<br>begin<br>&nbsp; //close 1<br>&nbsp; WindowCaption[1]:='Microsoft';<br>&nbsp; WindowClass[1]:='IE';<br>&nbsp; //close 2<br>&nbsp; WindowCaption[2]:='Microsoft';<br>&nbsp; WindowClass[2]:='#32770';<br>&nbsp; //close 3<br>&nbsp; WindowCaption[3]:='Explorer';<br>&nbsp; WindowClass[3]:='#32770';<br>&nbsp; //close 4<br>&nbsp; WindowCaption[4]:='安装语言';<br>&nbsp; WindowClass[4]:='#32770';<br>&nbsp; //close 5<br>&nbsp; WindowCaption[5]:='文件';<br>&nbsp; WindowClass[5]:='#32770';<br>&nbsp; //close 6<br>&nbsp; WindowCaption[6]:='ActiveX';<br>&nbsp; WindowClass[6]:='#32770';<br>&nbsp; //close 7<br>&nbsp; WindowCaption[7]:='Internet';<br>&nbsp; WindowClass[7]:='#32770';<br>&nbsp; //close 8<br>&nbsp; WindowCaption[8]:='Alert';<br>&nbsp; WindowClass[8]:='#32770';<br>&nbsp; //close 9<br>&nbsp; WindowCaption[9]:='Internet';<br>&nbsp; WindowClass[9]:='Internet';<br>&nbsp; //close 10<br>&nbsp; WindowCaption[10]:='安全设置';<br>&nbsp; WindowClass[10]:='#32770';<br>&nbsp; //close 11<br>&nbsp; WindowCaption[11]:='Script';<br>&nbsp; WindowClass[11]:='SCRDBG';<br>&nbsp; //close 12<br>&nbsp; WindowCaption[12]:='Script';<br>&nbsp; WindowClass[12]:='#32770';<br><br>&nbsp; hWndStart:=GetDesktopWindow;<br>&nbsp; hwndLike:=GetWindow(hWndStart,GW_CHILD);<br>&nbsp; while hwndLike&lt;&gt;0 do<br>&nbsp; begin<br>&nbsp; &nbsp; GetWindowText(hwndLike,@WndCaption,254);<br>&nbsp; &nbsp; GetClassName(hwndLike,@WndClassName,254);<br><br>&nbsp; &nbsp; for i:=1 to 12 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if ((pos(WindowCaption,StrPas(WndCaption))&lt;&gt;0) and<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (pos(WindowClass,StrPas(WndClassName))&lt;&gt;0)) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; PostMessage(hwndLike,WM_CLOSE,0,0 ); //找到匹配窗口名称与类名或窗口名称匹配<br>&nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; hwndLike:=GetWindow(hwndLike,GW_HWNDNEXT);<br>&nbsp; end;<br>end;<br>
 
关闭所有IE窗口的完整代码,首先 uses ComObj:<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; sh,IEs,IE:variant;<br>&nbsp; i:integer;<br>begin<br>&nbsp; sh:=CreateOleobject('shell.application');<br>&nbsp; IEs:=sh.windows;<br>&nbsp; for i:=IEs.count-1 downto 0 do<br>&nbsp; begin<br>&nbsp; &nbsp; IE:=IEs.item(i);<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; if pos('IEXPLORE.EXE',ie.fullname)&gt;0 then ie.Quit;<br>&nbsp; &nbsp; except<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>要关闭特定窗口可根据 IE.LocationURL 来判断!!!
 
sendmessage可以的<br>你肯定是句柄找错了<br><br>也可以用shellwindow来关闭
 
jsxjd的方法最简单得180分<br>其他人每人20分<br>谢谢各位的帮助,祝你们生活愉快:)
 
后退
顶部