单元文件如下:
unit getIE;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
procedure GetComboBoxData;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses mshtml;
{$R *.dfm}
procedure TForm1.GetComboBoxData;
var
ShellWindow: IShellWindows;
nCount: integer;
spDisp: IDispatch;
i, j, x, xx: integer;
vi, test: OleVariant;
IE1: IWebBrowser2;
IDoc1: IHTMLDocument2;
iELC: IHTMLElementCollection;
S: string;
HtmlInputEle: IHTMLInputElement;
HtmlSelEle: IHTMLSelectElement;
Htmloption: IHTMLOptionElement;
op: Ihtmlelement;
begin
ShellWindow := CoShellWindows.Create;
nCount := ShellWindow.Count;
for i := 0 to nCount - 1 do
begin
vi := i;
spDisp := ShellWindow.Item(vi);
if spDisp = nil then continue;
spDisp.QueryInterface(iWebBrowser2, IE1);
if IE1 <> nil then
begin
IE1.Document.QueryInterface(IHTMLDocument2, iDoc1);
if iDoc1 <> nil then
begin
ielc := iDoc1.Get_all;
for j := 0 to ielc.length - 1 do
begin
Application.ProcessMessages;
spDisp := ielc.item(J, 0);
if SUCCEEDED(spDisp.QueryInterface(IHTMLselectelement, HtmlSelEle)) then
with HtmlSelEle do
begin
SelectedIndex := 0;
for x := 0 to length-1 do
begin
spDisp := HtmlSelEle.item(x, 0);
if SUCCEEDED(spDisp.QueryInterface(IHTMLOptionElement, htmloption)) then
S := S + #9 + ' 索引号=' + IntToStr(SelectedIndex)
+ ' 下拉菜单名称=' + name
+ ' 选项值=' + value+'下拉框你要的值='+htmloption.text; ;
SelectedIndex := x+1;
end;
end;
end;
Memo1.Lines.Add(S);
Exit;
end;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
GetComboBoxData;
end;
end.