Mega Code Archive

 
Categories / Delphi / LAN Web TCP
 

Refreshing all Internet Explorer Windows

Title: Refreshing all Internet Explorer Windows? Question: It is possible to connect to a running instance of Internet Explorer version 4.0 or later using the SHDocVw.ShellWindows collection and you can do with it whatever you want (i.e. refresh). Answer: The ShellWindows collection is described in the Internet Client SDK as follows: The ShellWindows object represents a collection of the open windows that belong to the shell. In fact, this collection contains references to Internet Explorer as well as other windows belonging to the shell, such as the Windows Explorer. uses MSHTML_TLB, SHDocVw_TLB; procedure TForm1.Button1Click(Sender: TObject); var ShellWindow: IShellWindows; WB: IWebbrowser2; spDisp: IDispatch; IDoc1: IHTMLDocument2; k: Integer; begin // Create the shell windows interface ShellWindow := CoShellWindows.Create; // Walk the internet explorer windows for k := 0 to ShellWindow.Count do begin // Get the interface spDisp := ShellWindow.Item(k); if spDisp = nil then Continue; // QueryInterface for the IWebBrowser2 spDisp.QueryInterface(iWebBrowser2, WB); if WB nil then begin // QueryInterface for the Document WB.Document.QueryInterface(IHTMLDocument2, iDoc1); if iDoc1 nil then begin WB := ShellWindow.Item(k) as IWebbrowser2; // Call the Refresh method // WB.Refresh; end; end; end; end;