您可以通过执行以下操作来查询 IE 窗口的 Windows shell:
uses ShDocVw_Tlb; // or ShDocVw
if Doc = Nil then
exit;
if Doc.body = Nil then
exit;
var
i: Integer;
Browser: IWebBrowser2;
ShellWindows: IShellWindows;
Doc : IHtmlDocument2;
ShellWindows := CoShellWindows.Create;
for i := 0 to ShellWindows.Count - 1 do
if Supports(ShellWindows.Item(i), IWebBrowser2, Browser) then
begin
// do something with Browser instance, e.g compare the Url you're
// expecting with Browser.LocationUrl
// if it is, then you can get at the Html by something like
Browser.Document.QueryInterface(IHtmlDocument2, Doc);
if (Doc <> Nil) and (Doc.Body <> Nil) then
// access any of the Doc's properties, e.g. InnerHtml
end;
显然,当 Support 返回 true 时,您可以检查返回的浏览器以查找您要查找的内容。例如,您可以使用IHtmlDocument2
浏览器 Document 的界面(首先检查它是否不是 Nil)来访问其 DOM、HTML 等。我想TWebBrowser
如果您想要这样做,找到一个窗口相对简单。