如何从程序中获取指定浏览器(ie)页面的url地址(100分)

  • 主题发起人 主题发起人 stevensi
  • 开始时间 开始时间
S

stevensi

Unregistered / Unconfirmed
GUEST, unregistred user!
我想通过程序打开一个ie窗口,并获取这个窗口中的url
 
打开窗口:<br>ShellExecute(Handle, nil, 'http://www.123.com', nil, nil, SW_ShowNormal); <br><br>获得当前IE窗口URL:<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; ShellWindow: IShellWindows;<br>&nbsp; nCount: integer;<br>&nbsp; spDisp: IDispatch;<br>&nbsp; i: 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; spDisp.QueryInterface( iWebBrowser2, IE1 );<br>&nbsp; &nbsp; if IE1 &lt;&gt; nil then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; memo1.Lines.Add( 'Location: '+ie1.LocationName );<br><br>&nbsp; &nbsp; &nbsp; IE1.Document.QueryInterface(IHTMLDocument2,iDoc1);<br>&nbsp; &nbsp; &nbsp; if iDoc1 &lt;&gt; nil then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; memo1.Lines.add( 'Title: ' + IDOC1.Title );<br>&nbsp; &nbsp; &nbsp; &nbsp; memo1.Lines.add( 'Url: ' + IDOC1.url);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br>
 
但是如何获得程序打开的指定ie窗口的url呢?
 
仅第一行就搞不定<br>ShellWindow: IShellWindows;<br><br>哪来的数据类型?我查了delphi的帮助和winapi32的帮助,都没有它
 
在uses中加入shellapi才能用<br>ShellExecute(Handle, nil, 'http://www.123.com', nil, nil, SW_ShowNormal);
 
后退
顶部