Private Const GWL_EXSTYLE As Long = (-20)
Private Const WS_EX_RIGHT As Long = &H1000
Private Const WS_EX_LEFTSCROLLBAR As Long = &H4000
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 Enum AlignConstants
alignLeft = 0
alignRight = 1
End Enum
Private Sub Form_Load()
Dim x As Long
For x = 0 To Screen.FontCount - 1
List1.AddItem Screen.Fonts(x)
Next
Check1.Caption = "Align Scrollbar to Left"
Check2.Caption = "Align Text to Right"
End Sub
Private Sub Check1_Click()
'Since the values of the alignment Enum
'correspond to the two values of a checkbox,
'the checkbox value property can be used
'directly as the alignment style parameter.
ListScrollAlign List1, Check1.Value
End Sub
Private Sub Check2_Click()
ListBoxAlign List1, Check2.Value
End Sub
Private Sub ListBoxAlign(lb As ListBox, _
Optional ByVal Align As AlignConstants = alignLeft)
Dim nStyle As Long
With lb
nStyle = GetWindowLong(.hwnd, GWL_EXSTYLE)
Select Case Align
Case alignRight:
nStyle = nStyle Or WS_EX_RIGHT
Case alignLeft:
nStyle = nStyle And Not WS_EX_RIGHT
End Select
SetWindowLong .hwnd, GWL_EXSTYLE, nStyle
End With
End Sub
Private Sub ListScrollAlign(lb As ListBox, _
Optional ByVal Align As AlignConstants = alignRight)
Dim nStyle As Long
With lb
nStyle = GetWindowLong(.hwnd, GWL_EXSTYLE)
Select Case Align
Case alignRight:
nStyle = nStyle Or WS_EX_LEFTSCROLLBAR
Case alignLeft:
nStyle = nStyle And Not WS_EX_LEFTSCROLLBAR
End Select
SetWindowLong .hwnd, GWL_EXSTYLE, nStyle
End With
End Sub