1个回答
展开全部
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;
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;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询