SetwindowsHookEx WH_GETMESSAGE
看了下MSDN对hook方面的描述,就开始写了个测试程序,实现功能如下,拦截并屏蔽用户定义消息wm_user1
const wm_user1=WM_USER+12;
安装钩子:hHook:=SetwindowsHookEx(WH_GETMESSAGE,@GetMsgProc,0,GetCurrentThreadId());
function GetMsgProc(code:integer; // hook code
wParam:WPARAM; // removal option
lParam:LPARAM // message
):integer;stdcall;
var
myMsg:TMsg;
begin
if (code<>HC_ACTION) then
begin
result := CallNextHookEx(hHook,code,WParam,LParam);
exit;
end
else
begin
myMsg := PMsg(lParam)^;
if (myMsg.message=wm_user1) then
begin
myMsg.message:=WM_NULL;//瞎蒙的
Result :=1; end
else
begin
result := CallNextHookEx(hHook,code,WParam,LParam);
end;
end;
end;