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;
原理很简单,枚举窗口
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;