经过我一天的研究,要想通过浏览的网站来获取IE Object实例,可以通过
TShellWindows来枚举系统所有IE窗口来判断IE
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
Browser: IWebBrowser2;
sw : TShellWindows ;
begin
sw := TShellWindows.Create(Application);
try
for i := 0 to sw.Count - 1 do
begin
Browser := sw.Item(i) as IWebBrowser2;
// ShowMessage(Browser.LocationURL) ;
if Browser.LocationURL = 'http://www.163.net/' then
begin
// »ñµÃÄãËùÏëÒªµÄIE object
Browser.Navigate('www.sina.com.cn', EmptyParam, EmptyParam, EmptyParam, EmptyParam);
// Browser.Quit
Break;
end;
end;
finally
sw.Free ;
end;
end;