如何拦截(系统所有的) WM_DRAWITEM 和:WM_NCCALCSIZE:消息??? (100分)

  • 主题发起人 主题发起人 网中
  • 开始时间 开始时间

网中

Unregistered / Unconfirmed
GUEST, unregistred user!
如题;<br>我用钩子怎么拦截不到,请高手指点。谢谢<br>var<br>&nbsp;_Hook:HHOOK;<br>function HookHandler(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; <br>begin<br>&nbsp; Result := 0;<br>&nbsp; If iCode &lt; 0 Then Result := CallNextHookEx(NextHook, iCode, wParam, lParam);<br><br>&nbsp;case wparam of<br>&nbsp; WM_DRAWITEM:<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; //拦截事件<br>&nbsp; &nbsp; end;<br>&nbsp; WM_NCCALCSIZE:<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; //拦截事件<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>procedure HookOn(Wnd: HWND); stdcall;<br>begin<br>&nbsp; &nbsp;_Hook := &nbsp; SetWindowsHookEx(WH_GETMESSAGE, HookHandler, HInstance, 0); &nbsp;//全局<br>end;
 
试试<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; procedure WM_DRAWITEM(var msg: TMessage);message WM_DRAWITEM;<br><br>procedure TForm1.WM_DRAWITEM(var msg: TMessage);<br>begin<br>&nbsp; inherited;<br>&nbsp; showmessage(‘...........’);<br>end;
 
你的代码是拦不到任何消息的。<br><br>WH_GETMESSAGE类型的钩子,wParam参数是指定是否从消息队列中移走消息,lParam参数是指向MSG消息结构的指针,它的message域才是消息。<br><br>//如何拦截(系统所有的) WM_DRAWITEM 和:WM_NCCALCSIZE:消息??? <br>最好做在DLL中,一般非DLL类型的钩子只能拦截本进程的消息。
 
TO thx1180<br><br>我是放在DLL里。需要拦截系统所有的消息。能不能给出具体意见?
 
把:<br>case wparam of<br>改为:<br>case lParam.message of
 
TO thx1180<br>&nbsp; &nbsp;case lParam.message of<br><br>是放在那里?是<br>&nbsp;SetWindowsHookEx(WH_GETMESSAGE, HookHandler, HInstance, 0); &nbsp;指定的 HookHandler里吗?好象不行。能不能再具体些?谢谢
 
我是改的你的代码啊,就是在HookHandler里的。
 
to thx1180 <br><br>function HookHandler(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; <br>begin<br>&nbsp; Result := 0;<br>&nbsp; If iCode &lt; 0 Then Result := CallNextHookEx(NextHook, iCode, wParam, lParam);<br><br>// case wparam of<br>//改为<br>&nbsp;case lParam.message of//编译通不过啊<br>&nbsp; WM_DRAWITEM:<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; //拦截事件<br>&nbsp; &nbsp; end;<br>&nbsp; WM_NCCALCSIZE:<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; //拦截事件<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>procedure HookOn(Wnd: HWND); stdcall;<br>begin<br>&nbsp; &nbsp;_Hook := &nbsp; SetWindowsHookEx(WH_GETMESSAGE, HookHandler, HInstance, 0); &nbsp;//全局<br>end;
 
是这样:<br>case PMsg(lParam)^.message of
 
还是拦截不到所需消息
 
能把代码贴全一点么?你的NextHook是什么变量?<br>看CallNextHookEx的帮助,这个参数是指向当前HOOK的句柄,该用_Hook代替。
 
to thx1180<br><br>&nbsp;你的QQ?
 
多人接受答案了。
 
后退
顶部