'Definitions
Public 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
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Const GWL_WNDPROC = (-4)
Private Const WM_MOUSEWHEEL = &H20A
'Variables used
Dim Last as Long
Dim FormWnd as Long
'Here is the hook
FormWnd = FormName.hWnd
Last = SetWindowLong(FormWnd, GWL_WNDPROC, AddressOf MouseWheelWndProc)
'Here is the unhook
Call SetWindowLong(FormWnd, GWL_WNDPROC, Last) 'You must unhook the hook before exiting or your program will crash!
'Here is the function MouseWheelWndProc, it must be definied in a public modue
Public Function MouseWheelWndProc (ByVal hWnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If iMsg = WM_MOUSEWHEEL And hWnd = FormWnd Then
'Call a function in FormName
'To see if the wheel is going up or down: Value = (lParam And &HFFFF&)
End If
MouseWheelWndProc = CallWindowProc(Last, hWnd, iMsg, wParam, lParam)
End Function
This code will hook one window if you want to hook more than one you will have to store the LastProcedure addresses of each form to use it with the CallWindowProc and to unhook at the end.
I think you can find some samples on google.
You create a public sub for the control (I will work as an event you will call after checking the message).
All you need is the hWnd of your control (if it's a usercontrol then write UserControl.hWnd)
The code will work when the control will have focus and you'll scroll.
thanks for your help but I don`t know why, i can`t use it, If you could ,please just send a complectly example (with module,form,commandbotton)
Thanks again