以下方法好使
procedure WMActivate(var Msg: TWMActivate);message WM_Activate;
procedure TFormMain.WMActivate(var Msg: TWMActivate);
var
S: String;
wnd: HWND;
I: Integer;
begin
If Msg.Active=0 then
begin
wnd := Msg.ActiveWindow;
I := GetWindowTextLength(wnd);
SetLength(S, I + 1);
GetWindowText(Wnd, PChar(S), I + 1);
if Pos('Internet Explorer', S)>0 then
begin
// Sendmessage(wnd,WM_CLOSE,0,0);
Sendmessage(wnd,WM_KEYDOWN,VK_RETURN,0);
// showMessage('检测到弹出窗口!');
end;
end;
end;