可以用WH_GETMESSAGE类型的钩子解决
这是dll部分的代码
unit Unit1;
interface
uses SysUtils,Classes,Windows,Dialogs,Forms,Messages,Controls;
function hookproc(ncode:integer;wparam:wparam;lparam:lparam):LRESULT;stdcall;
procedure EnableHook;stdcall;export;
procedure DisableHook;stdcall;export;
var hhk:Cardinal;
implementation
function hookproc(ncode:integer;wparam:wparam;lparam:lparam):LRESULT;stdcall;
var p
MSG;
s:string;
begin
p:=PMSG(lparam);
s:=ExtractFileName(Application.ExeName);
if (s='iexplore.exe') or (s='IEXPLORE.EXE') then
begin
if p^.message=WM_CLOSE then
begin
if MessageDlg('Do you want to exit now?',mtConfirmation, [mbYes, mbNo], 0) = mrNo then
p^.message:=WM_USER+1;
end;
end;
result:=0;
end;
procedure EnableHook;stdcall;export;
begin
if hhk=0 then
begin
hhk:=SetWindowsHookEx(WH_GETMESSAGE,@hookproc,Hinstance,0);
end;
end;
procedure DisableHook;stdcall;export;
begin
if hhk<>0 then
begin
UnHookWindowsHookEx(hhk);
hhk:=0;
end;
end;
end.