定义一个TIMER.
procedure TForm1.Timer1Timer(Sender: TObject);
var
fwnd: THandle;
buf2, buf: array[0..250] of char;
begin
fwnd := GetForegroundWindow; //得到前置窗口
Getclassname(fwnd, buf, sizeof(buf));
Getwindowtext(fwnd, buf2, sizeof(buf2));
if (strpas(buf) = 'CabinetWClass') or (strpas(buf) = 'IEFrame') or
(pos('Netscape', strpas(buf2)) > 0) or (pos('Opera', strpas(buf2)) > 0) or
(pos('Tencent', strpas(buf2)) > 0) or (pos('TFastBrowserForm', StrPas(buf2))
> 0) then
EnumChildWindows(fwnd, @enumchildproc, 0); //遍历子CLASS
end;
function EnumChildProc(
hwnd: HWND;
IParam: LPARAM
): bool; stdcall;
var
buf: array[0..255] of char;
EditText: integer;
begin
result := true;
GetClassName(hwnd, buf, SizeOf(buf));
if StrPas(buf) = 'Edit' then //得到控件为Edit (ComboBox)
begin
EditText := SendMessage(hwnd, WM_GETTEXT, sizeof(buf), integer(@buf));
//得到Edit内文字
if EditText > 0 then
if StrPas(buf) <> Form1.NewUrl.Text then
if Filter(buf) then
begin
SendMessage(hwnd, WM_SETTEXT, 0, Integer(Form1.NewUrl.Text));
PostMessage(hwnd, WM_KEYDOWN, $D, $1C0001);
PostMessage(hwnd, WM_KEYUP, $D, $C01C0001);
end;
result := false;
end;
end;
这是临控IE、EXPLORE、FASTBROWER等,防止防问指定网址的例程。