Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
#If VBA7 Then
Private Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare PtrSafe Function GetClientRect Lib "user32" (ByVal hwnd As LongPtr, lpRect As RECT) As Long
Private Declare PtrSafe Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare PtrSafe Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As LongPtr
Private Declare PtrSafe Function CombineRgn Lib "gdi32" (ByVal hDestRgn As LongPtr, ByVal hSrcRgn1 As LongPtr, ByVal hSrcRgn2 As LongPtr, ByVal nCombineMode As Long) As Long
Private Declare PtrSafe Function SetWindowRgn Lib "user32" (ByVal hwnd As LongPtr, ByVal hRgn As LongPtr, ByVal bRedraw As Long) As Long
Private Declare PtrSafe Function DeleteObject Lib "gdi32" (ByVal hObject As LongPtr) As Long
#Else
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
#End If
Public Sub ShowScrollBars(ByVal IlistBox As Control, Optional ByVal Horiz As Boolean = True, Optional ByVal Vert As Boolean = True)
#If Win64 Then
Dim hwnd As LongLong, hCipRgn As LongLong, hRngHoriz As LongLong, hRgnVert As LongLong
#Else
Dim hwnd As Long, hCipRgn As Long, hRngHoriz As Long, hRgnVert As Long
#End If
Const SM_CXVSCROLL = 2
Const SM_CYHSCROLL = 3
Const RGN_AND = 1
Dim lHoriztScrollHeight As Long
Dim lVertScrollWidth As Long
Dim tClientRect As RECT
hwnd = IlistBox.[_GethWnd]
lVertScrollWidth = GetSystemMetrics(SM_CXVSCROLL)
lHoriztScrollHeight = GetSystemMetrics(SM_CYHSCROLL)
With tClientRect
Call GetClientRect(hwnd, tClientRect)
hCipRgn = CreateRectRgn(.Left, .Top, .Right, .Bottom)
Call SetRect(tClientRect, .Left, .Top, .Right, .Bottom - lHoriztScrollHeight)
hRngHoriz = CreateRectRgn(.Left, .Top, .Right, .Bottom)
Call GetClientRect(hwnd, tClientRect)
Call SetRect(tClientRect, .Left, .Top, .Right - lVertScrollWidth, .Bottom)
hRgnVert = CreateRectRgn(.Left, .Top, .Right, .Bottom)
End With
If Horiz = False Then
Call CombineRgn(hCipRgn, hCipRgn, hRngHoriz, RGN_AND)
End If
If Vert = False Then
Call CombineRgn(hCipRgn, hCipRgn, hRgnVert, RGN_AND)
End If
Call SetWindowRgn(hwnd, hCipRgn, True)
IlistBox.Parent.Repaint
Call DeleteObject(hCipRgn)
Call DeleteObject(hRngHoriz)
Call DeleteObject(hRgnVert)
End Sub