Author: Attila Torda-Pilisi Get the HTML Code out of all Internet Explorer Instances? Answer: 1 uses 2 MSHTML_TLB, ActiveX; 3 4 function GetHTMLCode(WB: IWebbrowser2; ACode: TStrings): Boolean; 5 var 6 ps: IPersistStreamInit; 7 s: string; 8 ss: TStringStream; 9 sa: IStream; 10 begin 11 ps := WB.document as IPersistStreamInit; 12 s := ''; 13 ss := TStringStream.Create(s); 14 try 15 sa := TStreamAdapter.Create(ss, soReference) as IStream; 16 Result := Succeeded(ps.Save(sa, Bool(True))); 17 if Result then 18 ACode.Add(ss.Datastring); 19 finally 20 ss.Free; 21 end; 22 end; 23 24 procedure TForm1.Button1Click(Sender: TObject); 25 var 26 ShellWindow: IShellWindows; 27 WB: IWebbrowser2; 28 spDisp: IDispatch; 29 IDoc1: IHTMLDocument2; 30 k: Integer; 31 begin 32 ShellWindow := CoShellWindows.Create; 33 // get the running instance of Internet Explorer 34 for k := 0 to ShellWindow.Count do 35 begin 36 spDisp := ShellWindow.Item(k); 37 if spDisp = nil then 38 Continue; 39 // QueryInterface determines if an interface can be used with an object 40 spDisp.QueryInterface(iWebBrowser2, WB); 41 if WB <> nil then 42 begin 43 WB.Document.QueryInterface(IHTMLDocument2, iDoc1); 44 if iDoc1 <> nil then 45 begin 46 WB := ShellWindow.Item(k) as IWebbrowser2; 47 begin 48 // Add HTML Code to Memo 49 Memo1.Lines.Add('****************************************'); 50 Memo1.Lines.Add(WB.LocationURL); 51 Memo1.Lines.Add('****************************************'); 52 GetHTMLCode(WB, Memo1.Lines); 53 end; 54 end; 55 end; 56 end; 57 end;