There are about 12 APIs that only work in a particular bitness. GetWindowLongPtr is 64-bit only.
However the code with slight modifications works equally well in both 32-bit & 64-bit if you use GetWindowLong instead.
No need for conditional compilation so it is much simpler
APIs
Code:
Declare PtrSafe Function GetWindow Lib "user32" (ByVal hwnd As LongPtr, ByVal wCmd As Long) As LongPtr'Declare PtrSafe Function GetWindowLongPtr Lib "user32" Alias "GetWindowLongPtrA" (ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr 'NOT USED - 64-bit ONLY
Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long) As Long 'Colin R -works in both 32-bit & 64-bit
Declare PtrSafe Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As LongPtr, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Declare PtrSafe Function GetScrollInfo Lib "user32" (ByVal hwnd As LongPtr, ByVal n As Long, lpScrollInfo As SCROLLINFO) As Long
Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
Get_Scrollbar_handle code reverts to what it was originally:
Code:
...
' scrollbar found, get style and verify it's the one we want
' (horiz = 137573172, vert = 137573173)
sbStyle = GetWindowLong(hWndSB, GWL_STYLE) 'Colin R
...
See v2 attached
With the exception of the few 64-bit only APIs such as GetWindowsLongPtr & GetTickCount64, conditional compilation is only needed to ensure code also works in 2007 and earlier. In such cases, I use conditional compilation code like this:
Code:
'APIs updated for 64/32-bit - Colin Riddington 16/09/2021
#If VBA7 Then ' 32/64 Bit Windows API calls for VBA 7 (A2010 or later)
Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hWnd As LongPtr, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare PtrSafe Function SetWindowOpacity Lib "user32" Alias "SetLayeredWindowAttributes" _
(ByVal hWnd As LongPtr, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
#Else
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowOpacity Lib "user32" Alias "SetLayeredWindowAttributes" _
(ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Public Declare Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
#End If
You're quite right that I missed the hWndSb variable earlier but it did still work in 32-bit A365.
Remember 32-bit VBA7 can use LongPtr variable correctly (handled as Long in 32-bit & LongLong in 64-bit).
Many thanks for doing the conversion. Its given me an idea for another issue that I want to explore.
Details to follow ... if my idea works