先取得当前聊天室的窗口的句柄,然后用如下代码获取该窗口中的所有输入框:
uses SHDocVw,MSHTML;
procedure GetIETextField(w:longint):TStringList;
var i,k:integer;
ShellWindow: IShellWindows;
IE:IWebBrowser2;
IDoc:IHTMLDocument2;
spDisp:IDispatch;
aInputText:IHTMLInputTextElement;
v:OLEVariant;
tmpList:TStringList;
begin
tmpList:=TStringList.Create;
ShellWindow:=CoShellWindows.Create;
for k:=0 to ShellWindow.Count-1 do
begin
v:=k;
spDisp:=ShellWindow.Item(v);
spDisp.QueryInterface(IWEBBROWSER2,IE);
if IE=nil then continue;
if IE.Get_HWND<>w then continue;
IDoc:=IE.Document as IHTMLDocument2;
if iDoc=nil then continue;
if Idoc.Frames.Length<>0 then continue;
for i:=0 to Idoc.all.length-1 do
begin
if Idoc=nil then Break;
spDisp:=Idoc.all.item(i,varEmpty);
if SUCCEEDED(spDisp.QueryInterface(IHTMLInputTextElement,aInputText)) then
if aInputText.value<>'' then //****//
tmpList.add('name:'+aInputText.name+' value:'+aInputText.value);
end;
break;
end;
result:=tmpList;
end;
如果要对特定的输入框,只需要在//****//那行进行判断:
if aInputText.name='xxxxxxx' then
来自:Mutex, 时间:2001-5-18 11:00:25, ID:535010
另外,
如果该页面为Frame或者iFrame形式,在上述代码的
if idoc.Frames.lenght<>0 then Continue那行再进行处理。