Boostez vos compétences Excel avec notre communauté !
Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !
Gestion du WM_MOUSEMOVE:
Tu n'interceptes pas les mouvements de la souris alors que pour moi c'est là que je édtermine si oui ou non la souris est sur le Control.
De mon point de vue, le faire sur un WM_MOUSEWHEEL uniquement c'est trop tard. On peut être complètement ailleurs.
et pourquoi voudrais tu que ça ne le soit pasGestion de l'erreur sur .TopIndex:
Il faut la capter et UnHooker.
'Molette souris  Up/Down Listbox , ComboBox , Frame
Private Function LowLevelMouseProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim pos As POINTAPI, obj As Object, r As Range, CtL
    Dim Bool
    On Error Resume Next
    GetCursorPos pos
    'je bloque mon test rectangle
    'If pos.Y < rct2.Top Or pos.Y > rct2.Bottom Or pos.X < rct2.Left Or pos.X > rct2.Right Then UnHookMouse: Exit Function
    'je met le tiens
CheckMouseIsOverTheBox:
    Bool = MouseIsOverTheBox
    If Not Bool Then
        Call UnHookMouse: Exit Function
    End If
    If (nCode = HC_ACTION) Then
        If wParam = WM_MOUSEWHEEL Then
            LowLevelMouseProc = True
            'et c'est ici que vous avez un probleme sur 64 vec le delay
            With ControlHooked
                Select Case TypeName(ControlHooked)    ' déplace l'ascenseur en fonction de la molette ' l'info est stockée dans lParam
                Case "ListBox", "ComboBox": If GetHookStruct(lParam).mouseData > 0 Then .TopIndex = .TopIndex - 1 Else .TopIndex = .TopIndex + 1
                Case "Frame": If GetHookStruct(lParam).mouseData > 0 Then .ScrollTop = .ScrollTop - 3 Else .ScrollTop = .ScrollTop + 3
                End Select
            End With
        End If
        Exit Function
    End If
    'partie gestion d'erreur
    DoEvents: Debug.Print Err.Number
    On Error GoTo 0
    
    'LowLevelMouseProc = CallNextHookEx(0&, nCode, wParam, ByVal lParam)
End Function
	Non, ça sert à rien de récupérer la position de la souris sur un MOUSEWHEEL.on a besoin de quoi???????? d'intercepter le message de la molette de la souris c'est tout
Ce n'est pas suffisant. Sur une erreur de .TopIndex il faut UnHooker. C'est pas suffisant de faire Resume Next.on gere les erreur globalement
Private Function LowLevelMouseProc(ByVal nCode As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
    Dim Obj As Object
    Dim DoNotCallNextHook As Boolean
    'Prevent Excel crash (e.g. Alt+F4 on UserForm with Hooked Control)
    On Error Resume Next
  
    'Test validité du ControlHooked
    Set Obj = ControlHooked
  
    'Le ControlHooked a disparu ?
    If Err.Number <> 0 Or Obj Is Nothing Then
        Err.Clear
        Call UnHookMouse
    Else
        If nCode = HC_ACTION Then
            If wParam = WM_MOUSEMOVE Then
                'Check if the mouse is still on the Control
                If Not MouseIsOverTheBox Then
                    Call UnHookMouse
                End If
            End If
          
            If wParam = WM_MOUSEWHEEL Then
                DoNotCallNextHook = True
              
                With ControlHooked
                    'Is the Window still there (.TopIndex in error) ?
                    Err.Clear
                  
                    '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
                  
                    'Is the Window still there (.TopIndex in error) ?
                    If Err.Number <> 0 Then
                        Err.Clear
                        Call UnHookMouse
                        Exit Function
                    End If
                End With
            End If
        End If
    End If
    If Not DoNotCallNextHook Then
        LowLevelMouseProc = CallNextHookEx(0&, nCode, wParam, ByVal lParam)
    Else
        LowLevelMouseProc = True
    End If
    On Error GoTo 0
End Function
	Private Function LowLevelMouseProc(ByVal nCode As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
    Dim Obj As Object
    Dim DoNotCallNextHook As Boolean
    'Prevent Excel crash (e.g. Alt+F4 on UserForm with Hooked Control)
    On Error Resume Next
 
    'Test validité du ControlHooked
    Set Obj = ControlHooked
 
    'Le ControlHooked a disparu ?
    If Err.Number <> 0 Or Obj Is Nothing Then
        Err.Clear
        Call UnHookMouse
    Else
        If nCode = HC_ACTION Then
            '!!!! et pourquoi attendre de bouger la souris pour savoir si on est dedans  le control
            '!!!je peux tres bien rester immobile et ne toucher que la mollette
            '!!!!au quel cas cette condition passera inapercue
            'If wParam = WM_MOUSEMOVE Then
                'Check if the mouse is still on the Control
                If Not MouseIsOverTheBox Then
                    Call UnHookMouse
                End If
            'End If
         
            If wParam = WM_MOUSEWHEEL Then
                DoNotCallNextHook = True
             
                With ControlHooked
                    'Is the Window still there (.TopIndex in error) ?
                    Err.Clear
                 
                    '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
                        '!!!!!on fait pareil que a fait pour le "-" mais l'inverse
                        If .TopIndex < .ListCount - ScrollStep Then .TopIndex = .TopIndex + ScrollStep
                    End If
                 
                    '!!!!!!!on peut donc supprimer toute cette gestion d'erreur
                    'Is the Window still there (.TopIndex in error) ?
                    'If Err.Number <> 0 Then
                       ' Err.Clear
                        'Call UnHookMouse
                        'Exit Function
                    'End If
                End With
            End If
        End If
    End If
    If Not DoNotCallNextHook Then
        LowLevelMouseProc = CallNextHookEx(0&, nCode, wParam, ByVal lParam)
    Else
        LowLevelMouseProc = True
    End If
    On Error GoTo 0
End Function
	'Molette souris  Up/Down Listbox , ComboBox , Frame
Private Function LowLevelMouseProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim pos As POINTAPI, obj As Object, r As Range, CtL
    Dim Bool
    
    '!!!! Gestion d'erreur généraliste
    '!!!! Couvre les erreurs générales et ignore les traitements particuliers nécessaires
    '!!!! Si le .TopIndex se plante il n'y a pas de UnHook, c'est juste Resume Next !!!!
    '!!!! Si le Control Hooked a disparu pour une raison ou une autre il n'y a pas de UnHook, c'est juste Resume Next !!!!
    '
    On Error Resume Next
    GetCursorPos pos
    'je bloque mon test rectangle
    'If pos.Y < rct2.Top Or pos.Y > rct2.Bottom Or pos.X < rct2.Left Or pos.X > rct2.Right Then UnHookMouse: Exit Function
    'je met le tiens
CheckMouseIsOverTheBox:
    '!!!! Pourquoi lancer la fonction lorsque c'est un WM_MOUSEWHEEL
    '!!!! Ça sert strictement à rien
    '
    Bool = MouseIsOverTheBox
    If Not Bool Then
        Call UnHookMouse: Exit Function
    End If
    If (nCode = HC_ACTION) Then
        If wParam = WM_MOUSEWHEEL Then
            LowLevelMouseProc = True
            'et c'est ici que vous avez un probleme sur 64 vec le delay
            With ControlHooked
                Select Case TypeName(ControlHooked)    ' déplace l'ascenseur en fonction de la molette ' l'info est stockée dans lParam
                Case "ListBox", "ComboBox": If GetHookStruct(lParam).mouseData > 0 Then .TopIndex = .TopIndex - 1 Else .TopIndex = .TopIndex + 1
                Case "Frame": If GetHookStruct(lParam).mouseData > 0 Then .ScrollTop = .ScrollTop - 3 Else .ScrollTop = .ScrollTop + 3
                End Select
            End With
        End If
        Exit Function
    End If
    'partie gestion d'erreur
    DoEvents: Debug.Print Err.Number
    On Error GoTo 0
    
    'LowLevelMouseProc = CallNextHookEx(0&, nCode, wParam, ByVal lParam)
End Function
	Private Function LowLevelMouseProc(ByVal nCode As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
    Dim DoNotCallNextHook As Boolean
    'Prevent Excel crash (e.g. Alt+F4 on UserForm with Hooked Control)
    On Error Resume Next ' Globale error gestion
    If ControlHooked Is Nothing Or Err.Number > 0 Then
        UnHookMouse
        Err.Clear: Exit Function
    Else
        If nCode = HC_ACTION Then
            If Not MouseIsOverTheBox Then Call UnHookMouse: Exit Function
            If wParam = WM_MOUSEWHEEL Then
                DoNotCallNextHook = True
                With ControlHooked
                      'Err.Clear  'absolutely useless
                    '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
                        '!!!!!on fait pareil que a fait pour le "-" mais l'inverse
                        If .TopIndex < .ListCount - ScrollStep Then .TopIndex = .TopIndex + ScrollStep
                    End If
                End With
            End If
        End If
    End If
    If Not DoNotCallNextHook Then
        'triggers a new  hook if an error is incurred
        LowLevelMouseProc = CallNextHookEx(0&, nCode, wParam, ByVal lParam)
    Else
        LowLevelMouseProc = True 'callback of function
    End If
    On Error GoTo 0 'close and empty  the stack of error
End Function
	We use cookies and similar technologies for the following purposes:
Est ce que vous acceptez les cookies et ces technologies?
We use cookies and similar technologies for the following purposes:
Est ce que vous acceptez les cookies et ces technologies?