怎么得到IE浏览器的网址输入框的句柄?困扰我很久了 浏览器

解决方案 »

  1.   

    用spy++抓
    原理很简单,枚举窗口
      

  2.   


    function GetIE6UrlHwnd: THandle;
    const
      CtlNames: array[0..4] of string = (
        'WorkerW',
        'ReBarWindow32',
        'ComboBoxEx32',
        'ComboBox',
        'Edit'
      );
    var
      i: integer;
    begin
      Result := FindWindow('IEFrame', nil);
      if Result = 0 then exit;  for i := 0 to Length(CtlNames) - 1 do
      begin
        Result := FindWindowEx(Result, 0, PChar(CtlNames[i]), nil);
        if Result = 0 then
          Break;
      end;
    end;function GetIE7UrlHwnd: THandle;
    const
      CtlNames: array[0..5] of string = (
        'WorkerW',
        'ReBarWindow32',
        'Address Band Root',
        'ComboBoxEx32',
        'ComboBox',
        'Edit'
      );
    var
      i: integer;
    begin
      Result := FindWindow('IEFrame', nil);
      if Result = 0 then exit;  for i := 0 to Length(CtlNames) - 1 do
      begin
        Result := FindWindowEx(Result, 0, PChar(CtlNames[i]), nil);
        if Result = 0 then
          Break;
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      Edit1.Text := IntToHex(GetIE7UrlHwnd, 8);
    end;