procedure OpenInIEAndFillForm(AURL: string; UserID, UserPsw: string);
var
i: Integer;
url, html: string;
Found: Boolean;
WinList: TWindowList;
Wnd, WndChild, Pid: HWND;
Items: TStrings;
sLine: string;
HTMLDocument, FrameDocument: IHTMLDocument2;
tmpHTMLElement, tmpHtmlElement1: IHTMLElement;
HTMLFramesCollection: IHTMLFramesCollection2;
zdName, zdType: string;
IE: IWebbrowser2;
sText: string;
userinputelement,pwdinputelement:ihtmlinputelement;
o: OleVariant;
j: Olevariant;
OneFrame:Ihtmlwindow2;
spdisp: IDispatch;
begin
Items := TStringList.Create;
try
if (UserID = '') or (UserPsw = '') then Exit;
//1、打开网页
ShellExecute(0, nil, PChar('C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE'), PChar(AUrl), nil, SW_SHOWNORMAL);
Sleep(1000);
//2、提取Iframe的句柄
wnd := 0;
WndChild := 0;
WinList := GetWindowList(0);
for i := Low(winlist) to High(winlist) do
begin
if WinList[i].ClassName = 'IEFrame' then
begin
Wnd := WinList[i].window;
Break;
end;
end;
if Wnd = 0 then Exit;
//3、提取IE对象
//1、IE6
WndChild := FindWindowEx(Wnd, 0, 'Shell DocObject View', nil);
Sleep(500);
WndChild := FindWindowEX(WndChild, 0, 'Internet Explorer_Server', nil);
//2、IE8
if WndChild = 0 then
begin
WndChild := FindWindowEx(Wnd, 0, 'Frame Tab', nil);
Sleep(300);
WndChild := FindWindowEx(WndChild, 0, 'TabWindowClass', nil);
Sleep(300);
WndChild := FindWindowEx(WndChild, 0, 'Shell DocObject View', nil);
i := 0;
Wnd := 0;
while True do
begin
Wnd := FindWindowEX(WndChild, 0, 'Internet Explorer_Server', nil);
if Wnd <> 0 then
begin
WndChild := Wnd;
Break;
end;
if i > 10 then Exit;
Inc(i);
Sleep(500);
end;
end;
//4、提取IE
i := 0;
while True do
begin
GetIEFromHWND(WndChild, IE);
if IE <> nil then Break;
Sleep(1);
inc(i);
if i > 10 then Break;
end;
//5、填表
if ie = nil then Exit;
HTMLDocument := Ie.Document as IHTMLDocument2;
HTMLFramesCollection := HTMLDocument.frames;
{
for i := 0 to HTMLFramesCollection.length - 1 do
begin
j := i;
spdisp := HTMLFramesCollection.item(j);
if SUCCEEDED(spDisp.QueryInterface(IHTMLWindow2, OneFrame)) then
begin
while True do
begin
o := OneFrame.document.all.item('logonCardNum', 0);
o.Value := UserID;
// o := OneFrame.document.all.item('logonCardPass', 0);
end;
Break;
end;
end; }
finally
Items.Free;
end;
end;
var
i: Integer;
url, html: string;
Found: Boolean;
WinList: TWindowList;
Wnd, WndChild, Pid: HWND;
Items: TStrings;
sLine: string;
HTMLDocument, FrameDocument: IHTMLDocument2;
tmpHTMLElement, tmpHtmlElement1: IHTMLElement;
HTMLFramesCollection: IHTMLFramesCollection2;
zdName, zdType: string;
IE: IWebbrowser2;
sText: string;
userinputelement,pwdinputelement:ihtmlinputelement;
o: OleVariant;
j: Olevariant;
OneFrame:Ihtmlwindow2;
spdisp: IDispatch;
begin
Items := TStringList.Create;
try
if (UserID = '') or (UserPsw = '') then Exit;
//1、打开网页
ShellExecute(0, nil, PChar('C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE'), PChar(AUrl), nil, SW_SHOWNORMAL);
Sleep(1000);
//2、提取Iframe的句柄
wnd := 0;
WndChild := 0;
WinList := GetWindowList(0);
for i := Low(winlist) to High(winlist) do
begin
if WinList[i].ClassName = 'IEFrame' then
begin
Wnd := WinList[i].window;
Break;
end;
end;
if Wnd = 0 then Exit;
//3、提取IE对象
//1、IE6
WndChild := FindWindowEx(Wnd, 0, 'Shell DocObject View', nil);
Sleep(500);
WndChild := FindWindowEX(WndChild, 0, 'Internet Explorer_Server', nil);
//2、IE8
if WndChild = 0 then
begin
WndChild := FindWindowEx(Wnd, 0, 'Frame Tab', nil);
Sleep(300);
WndChild := FindWindowEx(WndChild, 0, 'TabWindowClass', nil);
Sleep(300);
WndChild := FindWindowEx(WndChild, 0, 'Shell DocObject View', nil);
i := 0;
Wnd := 0;
while True do
begin
Wnd := FindWindowEX(WndChild, 0, 'Internet Explorer_Server', nil);
if Wnd <> 0 then
begin
WndChild := Wnd;
Break;
end;
if i > 10 then Exit;
Inc(i);
Sleep(500);
end;
end;
//4、提取IE
i := 0;
while True do
begin
GetIEFromHWND(WndChild, IE);
if IE <> nil then Break;
Sleep(1);
inc(i);
if i > 10 then Break;
end;
//5、填表
if ie = nil then Exit;
HTMLDocument := Ie.Document as IHTMLDocument2;
HTMLFramesCollection := HTMLDocument.frames;
{
for i := 0 to HTMLFramesCollection.length - 1 do
begin
j := i;
spdisp := HTMLFramesCollection.item(j);
if SUCCEEDED(spDisp.QueryInterface(IHTMLWindow2, OneFrame)) then
begin
while True do
begin
o := OneFrame.document.all.item('logonCardNum', 0);
o.Value := UserID;
// o := OneFrame.document.all.item('logonCardPass', 0);
end;
Break;
end;
end; }
finally
Items.Free;
end;
end;