Autres tester le scroll de la frame

patricktoulon

XLDnaute Barbatruc
bonjour à tous
est ce que plusieurs d'entre vous pourraient tester le scroll de la frame avec la mollette sur des versions 365 2019 et 2021 svp
merci pour les retours
 

Pièces jointes

  • scrollexemple 2.xlsm
    25.8 KB · Affichages: 13

Cousinhub

XLDnaute Barbatruc
Inactif
Re-,
J'ai modifié ici :
VB:
#If Win64 Then
Function LowLevelMouseProc(ByVal nCode As LongPtr, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
#Else
Function LowLevelMouseProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
1ère ligne, Long en LongPtr
La compil' donne une nouvelle erreur (ça avance....) :

1716274734368.png
 

patricktoulon

XLDnaute Barbatruc
bon
j'ai trouvé une de mes ancienne discussion ou j'avais résolu le problème sur 2016 64
il semblerait que tout ne doit pas être en longptr
VB:
Declare PtrSafe Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As LongPtr, ByVal hMod As LongPtr, ByVal dwThreadId As Long) As LongPtr
 

patricktoulon

XLDnaute Barbatruc
ou ca "any"
VB:
#If VBA7 Then
    Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal Destination As LongPtr, ByVal Source As LongPtr, ByVal Length As LongPtr)
    Declare PtrSafe Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As LongPtr, ByVal lpfn As LongPtr, ByVal hMod As LongPtr, ByVal dwThreadId As LongPtr) As LongPtr
    Declare PtrSafe Function CallNextHookEx Lib "user32" (ByVal hHook As LongPtr, ByVal nCode As LongPtr, ByVal wParam As LongPtr, lParam As LongPtr) As LongPtr
    Declare PtrSafe Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As LongPtr) As LongPtr
    Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
#Else
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal Destination As Long, ByVal Source As Long, ByVal Length As Long)
    Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hMod As Long, ByVal dwThreadId As Long) As Long
    Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
#End If
ajoute un debug pour voir ce que donne la structuremouse
VB:
#If Win64 Then
Function LowLevelMouseProc(ByVal nCode As LongPtr, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
#Else
Function LowLevelMouseProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
#End If
    On Error Resume Next 'en cas de mouvement très rapide,'évitons les crash en désactivant les erreurs
    Dim Criter As Boolean, i&
    GetCursorPos pos
    Criter = pos.X > EpC(0) And pos.X < EpC(2) And pos.Y > EpC(1) And pos.Y < EpC(3) 'recupère les coordonnée en pixel (left/top/right/bottom du control)
    If Not Criter Then UnHookMouse: Exit Function 'quand on est plus dans le périmètre du control bye bye !!
    If (nCode = HC_ACTION) Then
        If wParam = WM_MOUSEWHEEL Then
            LowLevelMouseProc = True
            With CtrlHooked
                Debug.Print "wParam : " & wParam & " /Lparam :" & lParam & "/ mousedatat : " & GetHookStruct(lParam).mouseData
                If GetHookStruct(lParam).mouseData > 0 Then .ScrollTop = .ScrollTop - 45 Else .ScrollTop = .ScrollTop + 45
            End With
        End If
        Exit Function
    End If
   LowLevelMouseProc = CallNextHookEx(0&, nCode, wParam, ByVal lParam)
    On Error GoTo 0
End Function
 

patricktoulon

XLDnaute Barbatruc
ok donc en long pour vb6 et longptr pour le vba7 (64 ou 32)
donc on a vu les déclarations
tu a modifié l'appel de la function ok on garde
si tu a bien débloqué le callnext en cas d'erreur il est rappelé
et après ça on a toujours un soucis avec lparam
il ne reste plus qu'une solution c'est comme je le dis depuis ce matin
c'est dans le bloc type pour la structure qu'il faut changer des trucs
car lparam doit renvoyer 0 ou quelque chose de faux

1716280740267.png
 

Cousinhub

XLDnaute Barbatruc
Inactif
Re-,
Donc, avec ce code :
VB:
'*****************************************************************************************************
'    ___     _     _______  __      _   ____  _   _  _______  ___     _   _   _    ___     _     _.
'   //  \\  /\\      //    // \\   //  //    //  //    //    //  \\  //  //  //   //  \\  //|   //
'  //___// //__\    //    //__//  //  //    //__//    //    //   // //  //  //   //   // // |  //
' //      //   \\  //    //  \\  //  //    //  \\    //    //   // //  //  //   //   // //  | //
'//      //    // //    //   // //  //___ //    \\  //     \\__// //__//  //___ \\__// //   |//
'****************************************************************************************************
'*******************************************
'hook mouse simplifié (molete souris sur frame)
'
'Author:patricktoulon
'-------------------------------------
'Exemple d'appel dans userform
'L'object appelant peut être un control dans la frame à scroller
'
'Sub Frame2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
' rouletambour Frame2
'End Sub
'------------------------------------
'code indenté avec Vba Indenter 3.1
'**********************************

Option Explicit
#If VBA7 Then
    Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal Destination As LongPtr, ByVal Source As LongPtr, ByVal Length As LongPtr)
    Declare PtrSafe Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As LongPtr, ByVal lpfn As LongPtr, ByVal hmod As LongPtr, ByVal dwThreadId As LongPtr) As LongPtr
    Declare PtrSafe Function CallNextHookEx Lib "user32" (ByVal hHook As LongPtr, ByVal nCode As LongPtr, ByVal wParam As LongPtr, lParam As LongPtr) As LongPtr
    Declare PtrSafe Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As LongPtr) As LongPtr
    Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As LongPtr
#Else
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal Destination As Long, ByVal Source As Long, ByVal Length As Long)
    Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
    Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
#End If

Type POINTAPI: X As LongPtr: Y As LongPtr: End Type
'Switch 64/32 pour la structure du hook de la souris
#If Win64 Then
    Private Type MSLLHOOKSTRUCT:
       'c'est dans cette partie qu'il faut trouver la faille
        pt As POINTAPI
        mouseData As LongPtr
        flags As LongPtr
        time As LongPtr
        dwExtraInfo As LongPtr
    End Type
#Else
    Private Type MSLLHOOKSTRUCT:
        'valable pour tout les version 32 d'excel vba7 ou vba 6
        'pour 32 ne pas déplacer mousedata et dwExtraInfo car soit ça crashe soit le scroll  ne fonctionne qu'en descente
        pt As POINTAPI
        mouseData As Long
        flags As Long
        time As Long
        dwExtraInfo As Long
    End Type
#End If

Const HC_ACTION = 0
Const WH_MOUSE_LL = 14
Const WM_MOUSEWHEEL = &H20A
Public udtlParamStuct As MSLLHOOKSTRUCT

Public plHooking As Long ' permet de savoir si le hook est activé ou pas

Public CtrlHooked As Object ' sera associé à la ListBox

Public pos As POINTAPI
Public EpC As Variant

Sub rouletambour(obj)
    'si ca n'a pas démarrer on demarre le hook
    If Not CtrlHooked Is Nothing Then If CtrlHooked.Name <> obj.Name Then UnHookMouse
    Call HookMouse(obj)
End Sub
'
Function GetHookStruct(ByVal lParam As LongPtr) As MSLLHOOKSTRUCT
    CopyMemory VarPtr(udtlParamStuct), lParam, LenB(udtlParamStuct)
    GetHookStruct = udtlParamStuct
End Function


#If Win64 Then
Function LowLevelMouseProc(ByVal nCode As LongPtr, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
#Else
Function LowLevelMouseProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
#End If
    On Error Resume Next 'en cas de mouvement très rapide,'évitons les crash en désactivant les erreurs
    Dim Criter As Boolean, i&
    GetCursorPos pos
    Criter = pos.X > EpC(0) And pos.X < EpC(2) And pos.Y > EpC(1) And pos.Y < EpC(3) 'recupère les coordonnée en pixel (left/top/right/bottom du control)
    If Not Criter Then UnHookMouse: Exit Function 'quand on est plus dans le périmètre du control bye bye !!
    If (nCode = HC_ACTION) Then
        If wParam = WM_MOUSEWHEEL Then
            LowLevelMouseProc = True
            With CtrlHooked
                If GetHookStruct(lParam).mouseData > 0 Then .ScrollTop = .ScrollTop - 45 Else .ScrollTop = .ScrollTop + 45
            End With
        End If
        Exit Function
    End If
    'LowLevelMouseProc = CallNextHookEx(0&, nCode, wParam, ByVal lParam)
    On Error GoTo 0
End Function
Public Sub HookMouse(ByVal ControlToScroll As Object, Optional ByVal FormName As String)
    If plHooking < 1 Then ' active le hook s'il n'avait pas déjà été activé
        EpC = EmplacementControl(ControlToScroll) 'on choppe le rectangle du control par raport à l'ecran(pas du parent!!!!) du control dans un array
        Set CtrlHooked = ControlToScroll
        plHooking = SetWindowsHookEx(WH_MOUSE_LL, AddressOf LowLevelMouseProc, 0, 0)
    End If
End Sub
Public Sub UnHookMouse()
    ' désactive le hook s'il existe
    If plHooking <> 0 Then UnhookWindowsHookEx plHooking: plHooking = 0: Set CtrlHooked = Nothing
End Sub
    ' fonction du calendar reconvertie
Function EmplacementControl(obj As Object)
    If Not obj Is Nothing Then
        Dim Lft As Double, Ltop As Double, ParentX As Object, ParentXInsWidth As Double, ParentXInsHeight As Double, K As Double, PPx, A, z
        Lft = obj.Left
        Ltop = obj.Top ' Normalement Page, Frame ou UserForm
        Set ParentX = obj.Parent
        With CreateObject("WScript.Shell"): PPx = 1 / (.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ThemeManager\LastLoadedDPI") / 72): End With
        Do
            ParentXInsWidth = ParentX.InsideWidth ' Le Page en est pourvu, mais pas le Multipage.
            ParentXInsHeight = ParentX.InsideHeight
            If TypeOf ParentX Is MSForms.Page Then Set ParentX = ParentX.Parent ' Prend le Multipage, car le Page est sans positionnement.
            K = (ParentX.Width - ParentXInsWidth) / 2: Lft = (Lft + ParentX.Left + K): Ltop = (Ltop + ParentX.Top + ParentX.Height - K - ParentXInsHeight)
            If Not (TypeOf ParentX Is MSForms.Frame Or TypeOf ParentX Is MSForms.MultiPage) Then Exit Do
            Set ParentX = ParentX.Parent
        Loop
        EmplacementControl = Array(Lft / PPx, Ltop / PPx, (Lft + obj.Width) / PPx, (Ltop + obj.Height) / PPx)
    End If
End Function

le résultat (après lancement de l'usf)
Incompatibilité de type sur :
1716282999575.png
 

Discussions similaires

Statistiques des forums

Discussions
315 093
Messages
2 116 140
Membres
112 669
dernier inscrit
Guigui2502