-
in form i have
i allway's get GPF !!! hyw ?
---
Private Sub Form_Load()
hook = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf WindProc)
End Sub
Private Sub Form_Unload(Cancel As Integer)
SetWindowLong Me.hwnd, GWL_WNDPROC, hook
hook = 0
End Sub
-------
module i have :
--------
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Form1.Caption = wMsg
WindProc = CallWindowProc(hook , hwnd&, wMsg&, wParam&, lParam&)
End Function
-
I don't have any subclassing exsamples on me right now, but at first glanse it looks correct.
However if you terminate a program, by pressing the stop button in VB, then the Form_Unload event won't be raised, and you'll get an error and a crash.
You must therefore always unhook everything manually before you close your program.
Also when using vb, there are problems asociated with stepping through code on a form, that is subclassed.
-
Have you placed Const GWL_WNDPROC = -4 at the top of you code signifying a constant.
If you have then check the return value in hook. It should be the address of the windows event handler function. If you get 0 then something obviously has gone wrong.
Apart from this your code is correct. I know this because I am using subclassing at the moment. If there are any particular bugs etc you come across when using subclassing or you need more help(i'll try to help anyway) then please emil me on mfesteba:yahoo.co.uk