1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| 'DECLARATION API
Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Declare Function GetSystemMetrics Lib "user32" _
(ByVal nIndex As Long) As Long
Public Declare Function SendMessage Lib _
"user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
'DECLARATION CONSTANTES
Public Const LB_GETHORIZONTALEXTENT = &H193
Public Const LB_SETHORIZONTALEXTENT = &H194
Public Const DT_CALCRECT = &H400
Public Const SM_CXVSCROLL = 2
'DECLARATION TYPE
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Sub ApplyScrollBar(fForm As Form, fList As ListBox)
Dim c As Long
Dim rcText As RECT
Dim newWidth As Long
Dim itemWidth As Long
Dim sysScrollWidth As Long
fForm.Font.Name = fList.Font.Name
fForm.Font.Bold = fList.Font.Bold
fForm.Font.Size = fList.Font.Size
sysScrollWidth = GetSystemMetrics(SM_CXVSCROLL)
For c = 0 To fList.ListCount - 1
Call DrawText(fForm.hdc, (fList.List(c)), -1&, rcText, DT_CALCRECT)
itemWidth = rcText.Right + sysScrollWidth
If itemWidth >= newWidth Then
newWidth = itemWidth
End If
Next
Call SendMessage(fList.hwnd, LB_SETHORIZONTALEXTENT, newWidth, ByVal 0&)
End Sub |
Partager