[RESOLVED] CallWindowProc
Hello,
I am trying to get my head around subclassing at the moment using SetWindowLong and CallWindowProc. So far it is a disaster. I am just trying to make a simple example.
VB Code:
Option Explicit
Private Declare Function CallWindowProc _
Lib "user32" _
Alias "CallWindowProcA" ( _
ByVal lpPrevWndFunc As Long, _
ByVal hWnd As Long, _
ByVal Msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) _
As Long
Private Declare Function SetWindowLong _
Lib "user32" _
Alias "SetWindowLongA" ( _
ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) _
As Long
Private Const GWL_WNDPROC = (-4)
Private Const WM_MOUSEMOVE = &H200
Private OldWindowProc As Long
Public Sub SubClass(frm As Form)
OldWindowProc = SetWindowLong(frm.hWnd, GWL_WNDPROC, AddressOf NewWindowProc)
End Sub
Public Sub UnSubClass(frm As Form)
Call SetWindowLong(frm.hWnd, GWL_WNDPROC, OldWindowProc)
End Sub
Public Function NewWindowProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, lParam As Long) As Long
If Msg = WM_MOUSEMOVE Then
Form1.Caption = "Mouse is moving..."
End If
NewWindowProc = CallWindowProc(OldWindowProc, hWnd, Msg, wParam, lParam)
End Function
The idea behind it is that i am trying to process the WM_MOUSEMOVE message once the mouse moves on the form, then it will display a message in the form caption to say that the mouse is being moved.
The best that it does at the moment is force VB to close and i get a GPF.
Any ideas on how i can make this work?
Re: [RESOLVED] CallWindowProc
You are correct. This is a in a code module because i didn't pass lParam by value caused me to get a GPF. As far as i am a aware you would not be able to use NewWindowProc in conjuction with AddressOf in a form, i don't think it would compile.