Ok .. maybe this will explain it a little better ...
Many controls in VB (all flavors) do not have an "OnScroll" event for the the mouse scroll, but windows forms does interpret it properly and allows you to hook into the event. That hook is what I am trying to set and trying to intercept with my callback procedure ...
This is the code I used in VB6 but I havn't been able to decipher the .net equivalent .. maybe I am looking too hard ...
Private Declare Function CallWindowProc Lib "user32.dll" 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.dll" Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private LocalHwnd As Long
Private LocalPrevWndProc As Long
Private MyForm As Form
Private Const GWL_WNDPROC = -4
Private Const WM_MOUSEWHEEL = &H20A
Private Function WindowProc(ByVal Lwnd As Long, ByVal Lmsg As Long, ByVal Wparam As Long, ByVal Lparam As Long) As Long
Dim MouseKeys As Long
Dim Rotation As Long
Dim Xpos As Long
Dim Ypos As Long
If Lmsg = WM_MOUSEWHEEL Then
MouseKeys = Wparam And 65535
Rotation = Wparam / 65536
Xpos = Lparam And 65535
Ypos = Lparam / 65536
MyForm.MouseWheel MouseKeys, Rotation, Xpos, Ypos
End If
WindowProc = CallWindowProc(LocalPrevWndProc, Lwnd, Lmsg, Wparam, Lparam)
End Function
Public Sub WheelHook(PassedForm As Form)
Set MyForm = PassedForm
LocalHwnd = PassedForm.hwnd
LocalPrevWndProc = SetWindowLong(LocalHwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub WheelUnHook()
SetWindowLong LocalHwnd, GWL_WNDPROC, LocalPrevWndProc
Set MyForm = Nothing
End Sub
Then in my form I have my event defined
Public Sub MouseWheel(ByVal MouseKeys As Long, ByVal Rotation As Long, ByVal Xpos As Long, ByVal Ypos As Long)
Dim NewValue As Long
With MyForm.VScroll
If Rotation > 0 Then
NewValue = .Value - .LargeChange
If NewValue < .Min + 1 Then
NewValue = .Min + 1
End If
Else
NewValue = .Value + .LargeChange
If NewValue > .Max Then
NewValue = .Max
End If
End If
.Value = NewValue
End With
End Sub
Ideally the event would be supported .. but alas it isn't so far as I know .. if it were supported, then I wouldn't have to define and store multiple hooks for each control .... and in the unlikely event there is a problem we don't compromize the stability of the system .. as you probably know well, if a hooked procedure is not unhooked, it can cause some serious problems when the control no longer exists.