'https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms644986(v=vs.85)
Private Function LowLevelMouseProc(ByVal nCode As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
Dim Bool As Boolean
Dim ErrNumber As Long
'Dim Obj As Object
Dim TopIndex As Long
'Dim DoNotCallNextHook As Boolean
' Static LastTimer As Single
'Test validité du ControlHooked
'On Error Resume Next
'Set Obj = ControlHooked
'ErrNumber = Err.Number: Debug.Print "ControlHooked est le control: erreur " & ErrNumber
'On Error GoTo 0
'Le ControlHooked a disparu (UserForm fermé Alt + F4 par exemple)
'If ErrNumber <> 0 Or ControlHooked Is Nothing Then
' Call UnHookMouse
' Else
If nCode = HC_ACTION Then
'If Int((Timer - LastTimer) * 100) >= 0 Then
If wParam = WM_MOUSEMOVE Then
'Debug.Print "addresse structure hookmouse:" & lParam
'DoNotCallNextHook = True
'Either on WM_MOUSEMOVE or on WM_MOUSEWHEEL
GoSub CheckMouseIsOverTheBox
End If
If wParam = WM_MOUSEWHEEL Then
LowLevelMouseProc = 1 ' la fonction est récursive!!!!!!!!!!!!!!!!!
'DoNotCallNextHook = True
'Either on WM_MOUSEMOVE or on WM_MOUSEWHEEL
'GoSub CheckMouseIsOverTheBox
If Not plHooking = 0 Then
With ControlHooked
'Is the Window still there ?
TopIndex = .TopIndex
On Error Resume Next
.TopIndex = 0: Debug.Print "erreur topindex"
ErrNumber = Err.Number
On Error GoTo 0
If ErrNumber <> 0 Then
Call UnHookMouse
Exit Function
End If
.TopIndex = TopIndex
'Moves the ScrollBar depending on the mouse wheel, Info is stored in lParam
If GetHookStruct(lParam).mouseData > 0 Then
If .TopIndex < ScrollStep Then .TopIndex = 0 Else .TopIndex = .TopIndex - ScrollStep
Else
.TopIndex = .TopIndex + ScrollStep
End If
End With
End If
'End If
'End If
End If
End If
'If Not DoNotCallNextHook Then
'Debug.Print "rappel de secour"
'LowLevelMouseProc = CallNextHookEx(0&, nCode, wParam, ByVal lParam)
'End If
'LastTimer = Timer
Exit Function
CheckMouseIsOverTheBox:
If Not ControlHooked Is Nothing Then
On Error Resume Next
Bool = MouseIsOverTheBox: Debug.Print "MouseIsOverTheBox " & Bool
ErrNumber = Err.Number:: Debug.Print "MouseIsOverTheBox " & ErrNumber
On Error GoTo 0
'Run time Error 57097: le résultat de l'appel à la fonction MouseMoveFunction() n'est pas significatif, on oublie !
If ErrNumber <> 57097 Then
If ErrNumber = 0 Then
'The mouse is not anymore over the ControlHooked Object
If Not Bool Then
Call UnHookMouse
End If
End If
End If
End If
Return
End Function