在IE中打开资源获取文档对象

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;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值