Thema Datum  Von Nutzer Rating
Antwort
27.01.2022 08:11:47 Siggi
NotSolved
27.01.2022 09:41:11 volti
NotSolved
Rot Scroll in Listbox 64bit Version scrollt nur nach oben
27.01.2022 10:46:35 volti
NotSolved
27.01.2022 11:00:09 Siggi
NotSolved
27.01.2022 11:10:20 Siggi
NotSolved
27.01.2022 11:26:39 volti
NotSolved
27.01.2022 19:33:55 Gast85208
NotSolved
27.01.2022 19:20:41 Gast85208
NotSolved
31.01.2022 08:18:32 Siggi
NotSolved
31.01.2022 10:22:57 volti
NotSolved
31.01.2022 10:52:25 Siggi
NotSolved

Ansicht des Beitrags:
Von:
volti
Datum:
27.01.2022 10:46:35
Views:
457
Rating: Antwort:
  Ja
Thema:
Scroll in Listbox 64bit Version scrollt nur nach oben

Hallo Siggi,

vergiss meinen Beitrag von eben, ich war noch nicht ausgeschlafen und kann ihn nicht löschen :-)

Ich hatte jetzt länger Zeit und habe Deinen Code überarbeitet. Teste ihn mal und wenn es immer noch nicht gehen sollte, bräuchte man mal am besten die Datei zum Testen.

Offensichtilich hast Du alle Longs in LongPtr umgeändert. Das geht natürlich nicht, denn somit hast Du auch die Konstanten verändert.

Geändert werden müssen die Functions GetWindowlong (die sind unterschiedlich zwischen 32 und 64 Bit) und WindowfromPoint (welche ebenfalls unterschiedlich sind). Für WindowFromPoint kann man mit einem Variablentrick das für 32 und 64-Bit in einer Function zusammenfassen.

Bitte teste mal....

Code:
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
 
Option Explicit

Private Type POINTAPI
     XY As Currency
End Type

Private Type MOUSEHOOKSTRUCT
     Pt As POINTAPI
     hwnd As LongPtr
     wHitTestCode As LongPtr
     dwExtraInfo As LongPtr
End Type

Private Declare PtrSafe Function FindWindow Lib "user32" _
        Alias "FindWindowA" ( _
        ByVal lpClassName As String, _
        ByVal lpWindowName As StringAs LongPtr
        #If Win64 Then
  Private Declare PtrSafe Function GetWindowLong Lib "user32" _
          Alias "GetWindowLongPtrA" ( _
          ByVal hwnd As LongPtr, _
          ByVal nIndex As LongAs LongPtr
        #Else
  Private Declare PtrSafe Function GetWindowLong Lib "user32" _
          Alias "GetWindowLongA" ( _
          ByVal hwnd As LongPtrByVal nIndex As LongAs LongPtr
        #End If

Private Declare PtrSafe Function SetWindowsHookEx Lib "user32" _
        Alias "SetWindowsHookExA" ( _
        ByVal idHook As LongPtr, _
        ByVal lpfn As LongPtr, _
        ByVal hmod As LongPtr, _
        ByVal dwThreadId As LongPtrAs LongPtr

Private Declare PtrSafe Function CallNextHookEx Lib "user32" ( _
        ByVal hHook As LongPtr, _
        ByVal nCode As LongPtr, _
        ByVal wParam As LongPtr, _
        lParam As AnyAs LongPtr

Private Declare PtrSafe Function UnhookWindowsHookEx Lib "user32" ( _
        ByVal hHook As LongPtrAs LongPtr

Private Declare PtrSafe Function PostMessage Lib "user32.dll" _
        Alias "PostMessageA" ( _
        ByVal hwnd As LongPtr, _
        ByVal wMsg As LongPtr, _
        ByVal wParam As LongPtr, _
        ByVal lParam As LongPtrAs LongPtr

Private Declare PtrSafe Function WindowFromPoint Lib "user32" ( _
        ByVal Point As CurrencyAs LongPtr

Private Declare PtrSafe Function GetCursorPos Lib "user32.dll" ( _
        ByRef lpPoint As POINTAPIAs LongPtr

Private Const WH_MOUSE_LL    As Long = 14
Private Const WM_MOUSEWHEEL  As Long = &H20A
Private Const HC_ACTION      As Long = 0
Private Const GWL_HINSTANCE  As Long = (-6)

Private Const WM_KEYDOWN     As Long = &H100
Private Const WM_KEYUP       As Long = &H101
Private Const VK_UP          As Long = &H26
Private Const VK_DOWN        As Long = &H28
Private Const WM_LBUTTONDOWN As Long = &H201

Private mLngMouseHook As LongPtr
Private mListBoxHwnd  As LongPtr
Private mbHook As Boolean

Sub HookListBoxScroll()
  Dim lngAppInst      As LongPtr
  Dim hwndUnderCursor As LongPtr
  Dim tPT As POINTAPI

  GetCursorPos tPT
  hwndUnderCursor = WindowFromPoint(tPT.XY)
  If mListBoxHwnd <> hwndUnderCursor Then
     UnhookListBoxScroll
     mListBoxHwnd = hwndUnderCursor
     lngAppInst = GetWindowLong(mListBoxHwnd, GWL_HINSTANCE)
     PostMessage mListBoxHwnd, WM_LBUTTONDOWN0&0&
     If Not mbHook Then
        mLngMouseHook = SetWindowsHookEx(WH_MOUSE_LLAddressOf MouseProc, lngAppInst, 0)
        mbHook = mLngMouseHook <> 0
     End If
  End If
End Sub

Sub UnhookListBoxScroll()
  If mbHook Then
     UnhookWindowsHookEx mLngMouseHook
     mLngMouseHook = 0
     mListBoxHwnd = 0
     mbHook = False
  End If
End Sub

Private Function MouseProc( _
  ByVal nCode As LongPtrByVal wParam As LongPtr, _
  ByRef lParam As MOUSEHOOKSTRUCTAs LongPtr
  On Error GoTo errH        ' Resume Next
  If (nCode = HC_ACTIONThen
     If WindowFromPoint(lParam.Pt.XY) = mListBoxHwnd Then
        If wParam = WM_MOUSEWHEEL Then
           MouseProc = True
           If lParam.hwnd > 0 Then
              PostMessage mListBoxHwnd, WM_KEYDOWNVK_UP0
           Else
              PostMessage mListBoxHwnd, WM_KEYDOWNVK_DOWN0
           End If
           PostMessage mListBoxHwnd, WM_KEYUPVK_UP0
           Exit Function
        End If
     Else
        UnhookListBoxScroll
     End If
  End If
  MouseProc = CallNextHookEx( _
  mLngMouseHook, nCode, wParam, ByVal lParam)
  Exit Function
errH:
  UnhookListBoxScroll
End Function
_________
viele Grüße
Karl-Heinz

Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
27.01.2022 08:11:47 Siggi
NotSolved
27.01.2022 09:41:11 volti
NotSolved
Rot Scroll in Listbox 64bit Version scrollt nur nach oben
27.01.2022 10:46:35 volti
NotSolved
27.01.2022 11:00:09 Siggi
NotSolved
27.01.2022 11:10:20 Siggi
NotSolved
27.01.2022 11:26:39 volti
NotSolved
27.01.2022 19:33:55 Gast85208
NotSolved
27.01.2022 19:20:41 Gast85208
NotSolved
31.01.2022 08:18:32 Siggi
NotSolved
31.01.2022 10:22:57 volti
NotSolved
31.01.2022 10:52:25 Siggi
NotSolved