下面是我以前写的获取当前打开页面的URL
procedure TFrm_main.Timer1Timer(Sender: TObject);
var
fwnd,hwnd:thandle;
buf2,buf:array[0..250] of char;
begin
fwnd:=GetForegroundWindow;
hwnd:=fwnd;
tishi:=1;
Getclassname(fwnd,buf,sizeof(buf));
Getwindowtext(fwnd,buf2,sizeof(buf2));
if (pos('任务管理器',strpas(buf2))>0) then
Postmessage(hwnd,WM_Close,0,0);
if (strpas(buf)='CabinetWClass') or(strpas(buf)='IEFrame') or (pos('Netscape',strpas(buf2))>0) or (pos('MyIE',strpas(buf2))>0) or (pos('Opera',strpas(buf2))>0) or (pos('Tencent',strpas(buf2))>0) or (pos('浏览',strpas(buf2))>0) then
begin
if (stop>0)and((strpas(buf)='IEFrame') or (pos('Netscape',strpas(buf2))>0) or (pos('MyIE',strpas(buf2))>0) or (pos('Opera',strpas(buf2))>0) or (pos('Tencent',strpas(buf2))>0)) then
begin
Postmessage(hwnd,WM_Close,0,0);
if oldwnd<>hwnd then
begin
application.MessageBox('现已关闭上网功能!','提示',mb_ok);
oldwnd:=hwnd;
end;
end
else if not (EnumChildWindows(fwnd,@enumchildproc,0)) then
begin
Postmessage(hwnd,WM_Close,0,0);
if (oldwnd<>hwnd) and (tishi=1) then
begin
//application.MessageBox('发现输入非法网站,现已关闭!','提示',mb_ok);
Application.CreateForm(TF_CloseIEPrompt, F_CloseIEPrompt);
F_CloseIEPrompt.Show;
oldwnd:=hwnd;
end;
end;
end;
end;
function EnumChildProc(hwnd:HWND;IParam:LPARAM):bool;stdcall;
var buf:array[0..250] of char;
rsize:integer;
str:string;
begin
result:=true;
Getclassname(hwnd,buf,sizeof(buf));
if strpas(buf)='Edit' then
begin
rsize:=sendmessage(hwnd,WM_GETTEXT,sizeof(buf),integer(@buf));
if rsize>0 then
begin
str:=buf; //这就是当前打开页面的URL
if (filter(buf)) then
begin
result:=false;
end;
end;
end;
end;