procedure TForm1.Button1Click(Sender: TObject); var ShellWindow: IShellWindows; ie :IWebBrowser2; i,j : Integer; V,vInput : OleVariant; sp:IDispatch; idoc:IHTMLDocument2; aInput :IHTMLInputButtonElement; begin ShellWindow := CoShellWindows.Create; for i:=0 to ShellWindow.Count-1 do begin V := i; sp := ShellWindow.Item(V); sp.QueryInterface(IWebBrowser2,ie); if ie<>nil then begin if ie.LocationURL='http://www.sohu.com' then begin ie.Document.QueryInterface(IHTMLDocument2,idoc); if idoc<>nil then begin for j:=0 to idoc.all.Length-1 do begin sp := idoc.all.item(j,varEmpty); if SUCCEEDED(sp.QueryInterface(IHTMLInputButtonElement,aInput)) then begin if aInput.value='登录' then begin vInput := aInput; vInput.Click; Break; end; end; end; end; Break; end; end; end; end;
var w: HWND; begin w := FindWindow( nil, '123' ); SendMessage( w, WM_COMMAND, 1, GetDlgItem(w, 1) ); end;
var
ShellWindow: IShellWindows;
ie :IWebBrowser2;
i,j : Integer;
V,vInput : OleVariant;
sp:IDispatch;
idoc:IHTMLDocument2;
aInput :IHTMLInputButtonElement;
begin
ShellWindow := CoShellWindows.Create;
for i:=0 to ShellWindow.Count-1 do
begin
V := i;
sp := ShellWindow.Item(V);
sp.QueryInterface(IWebBrowser2,ie);
if ie<>nil then
begin
if ie.LocationURL='http://www.sohu.com' then
begin
ie.Document.QueryInterface(IHTMLDocument2,idoc);
if idoc<>nil then
begin
for j:=0 to idoc.all.Length-1 do
begin
sp := idoc.all.item(j,varEmpty);
if SUCCEEDED(sp.QueryInterface(IHTMLInputButtonElement,aInput)) then
begin
if aInput.value='登录' then
begin
vInput := aInput;
vInput.Click;
Break;
end;
end;
end;
end;
Break;
end;
end;
end;
end;
w: HWND;
begin
w := FindWindow( nil, '123' );
SendMessage( w, WM_COMMAND, 1, GetDlgItem(w, 1) );
end;