高手请进:已知IE窗口的句柄,如何由此得到IHTMLdocument2接口?
对于delphi自带的TWebBrowser控件,可容易地得到IHTMLdocument2接口(代码如下)
但若只知道某IE窗口的句柄,如何由此得到该窗口的IHTMLdocument2接口?
Thanks in advance.
///////////////////////////////////////////////////////////////////////
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls, ActiveX, MSHtml;
type
TForm1 = class(TForm)
Button1: TButton;
WebBrowser1: TWebBrowser;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
doc:IHTMLdocument2;
elem:IHTMLElement;
begin
try
doc:=WebBrowser1.document as IHTMLdocument2;
if doc = nil then
begin
self.Caption := 'NULL';
end
else
begin
elem:=doc.all.item('mybuttonid',0) as IHTMLElement;
elem.click;
end
except
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
WebBrowser1.Navigate('c:\temp\html.html');
end;
end.