如果弹出的是浏览器窗口,可以通过地址来判断。
以下程序可用来获得所有已打开的IE浏览器窗口中的访问地址!!!!!
43. 获得IE中的浏览地址
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),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;