太
太阳火
Unregistered / Unconfirmed
GUEST, unregistred user!
我是想拦截WM_INITDIALOG消息,得到messagebox的句柄,可是下面的代码总是出错,access violation.<br><br>unit myunit;<br><br>interface<br><br>implementation<br><br>uses<br> Windows, Messages,<br><br>var<br> gHook: Hwnd;<br> oldProc: Pointer;<br><br>function HookWndProc(AHwnd: Hwnd; uMsg: Cardinal; wP: WParam; lP: LParam): LRESULT;<br>begin<br> Result := CallWindowProc(oldProc, AHwnd, uMsg, wP, lP);<br> if uMsg = WM_INITDIALOG then<br> begin<br> //取得了messagebox的hwnd, 做我的事情<br> end;<br>end;<br><br>function SetHook(nCode: integer; wP: WParam; lP: LParam): LRESULT;<br>begin<br> if (nCode = HC_ACTION) and (PCwpStruct(lP).message = WM_INITDIALOG) then<br> begin<br> oldProc := Pointer(GetWindowLong(PCwpStruct(lP).hwnd, GWL_WNDPROC));<br> SetWindowLong(PCwpStruct(lP).hwnd, GWL_WNDPROC, Longint(@HookWndProc));<br> end;<br><br> Result := CallNextHookEx(gHook, nCode, wP, lP);<br>end;<br><br>initialization<br><br>gHook := SetWindowsHookEx(WH_CALLWNDPROC, @SetHook, 0, GetCurrentThreadId);<br><br>finalization<br><br>UnhookWindowsHookEx(gHook);<br><br>end.