|
-
Dec 16th, 2006, 06:15 PM
#1
Thread Starter
Hyperactive Member
[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?
-
Dec 16th, 2006, 06:51 PM
#2
Re: CallWindowProc
VB Code:
Public Function NewWindowProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, [B]ByVal [/B]lParam As Long) As Long
-
Dec 16th, 2006, 06:55 PM
#3
Thread Starter
Hyperactive Member
-
Dec 16th, 2006, 07:27 PM
#4
Re: CallWindowProc
I could be wrong about this but in order to do subclassing I believe that CallWindowProc needs to be in a code module.
-
Dec 16th, 2006, 08:09 PM
#5
Thread Starter
Hyperactive Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|