SetwindowsHookEx WH_GETMESSAGE
看了下MSDN对hook方面的描述,就开始写了个测试程序,实现功能如下,拦截并屏蔽用户定义消息wm_user1
const wm_user1=WM_USER+12;
安装钩子:hHook:=SetwindowsHookEx(WH_GETMESSAGE,@GetMsgProc,0,GetCurrentThreadId());
- Delphi(Pascal) code
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 [color=#FF0000]myMsg.message:=WM_NULL;//瞎蒙的 Result :=1;[/color] end else begin result := CallNextHookEx(hHook,code,WParam,LParam); end; end;end;
然后用PostMessage(self.Handle,wm_user1,0,0);不过测试后发现不能屏蔽wm_user1消息,应该是我没操作好,文档没写清楚,不知道红色的地方该怎么改,特请大家帮个忙,谢谢。(备注:鼠标键盘钩子以前用简单点的还很成功,第一次尝试下用WH_GETMESSAGE拦截其他类型的消息,写的很差就别批评)
[解决办法]
代码似乎没问题,你对WM_user1的定义是否是正确的?
[解决办法]
拦截消息时,能否进入到GetMsgProc代码中,wm_user1是否定义的与用户的一致
[解决办法]
你咋不把你的正确的贴出来呢,顺便给我讲下hook嘛,
一起学习!