RSS订阅 | 匿名投稿
您的位置:网站首页 > 系统 > 正文

delphi获取IE浏览器Url地址

作者:admin 来源:未知 日期:2010/6/8 14:32:37 人气: 标签:

function GetIEAddress(IEHandle:THandle;var Address:string):Boolean;
Const WM_GETTEXT = $D;
WM_GETTEXTLENGTH =$E;
CtlNames:array[0..4] of string=(
WorkerA, //获得IE窗口的工作区的句柄
ReBarWindow32, //获得IE窗口的菜单栏的句柄
ComboBoxEx32, //获得IE窗口的下拉菜单的句柄
ComboBox, //获得IE窗口的下拉菜单当前项的句柄
Edit //获得这个下拉菜单的编辑框句柄
);
var
hwnd :THandle;
i,AddLen:integer;
AddBuf :Array[0..4095] of char;
s :string;
begin
Result:=True;
hwnd:=IEHandle;
try
for i:=0 to length(ctlnames)-1 do
hwnd:=FindWindowEx(hwnd,0,PChar(CtlNames[i]),nil);
except
Result:=false;
end;
if (Result) then begin
AddLen:=SendMessage(Hwnd,WM_GETTEXTLENGTH,0,0);
//向系统发送获得IE窗口的地址栏中的字符串长度命令
SendMessage(Hwnd,WM_GETTEXT,AddLen+1,DWord(@AddBuf));
//向系统发送获得IE窗体地址栏中的字符串命令
if length(AddBuf)>0 then
begin
Address:=AddBuf;
GetWindowText(IEHandle,AddBuf,length(AddBuf)+1);
s:=Addbuf;
i:=pos(Uppercase( - Microsoft Internet Explorer),
Uppercase(s));
if i>0 then s:=Trim(copy(s,1,i-1));
Address:=Address+ [+s+];
end
else Result:=false;
end;
end;

function EnumIEProc(hwnd:THandle;Param:LPARAM):Boolean;stdcall;
const NAME_LEN=1024;
type
PStrings=^TStrings;
var
sClassName:Array[0..NAME_LEN] of char;
IEAddress:string;
AddLen:Integer;
begin
AddLen:=GetClassName(hwnd,@sClassName,NAME_LEN);
if (AddLen=7) and (sClassName=IEFrame) then
if GetIEAddress(hwnd,IEAddress) then
PStrings(Param).Add(IEAddress);
Result:=true;
end;

function GetAllIEAddress(var Addresses:TStrings):Integer;
var
s:TStrings;
begin
s:=TStringList.Create ;
EnumWindows(@EnumIEProc,LPARAM(@s));
Result:=s.Count ;
if Result>0 then Addresses.Assign (s);
s.free;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
s:TStrings;
begin
s:=TStringList.Create ;
GetAllIEAddress(s);
if s.Count >0 then Memo1.Lines.Assign (s);
s.free;
end;

读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址: