Nel senso che avevo cercato di adattare il codice dello spunto al mio progetto, ma mi dava continui errori di vario tipo.
Comunque, sul progetto di prova dove avevo inserito il codice che ho postato precedentemente, ho provato ad inserire il tutto nel Modulo, come da tue indicazioni, lasciando solo la Load_Form nella form. Ma mi dà degli errori. Questo è il codice inserito nel Modulo:
Public Enum AlignConstants
Private Const GWL_EXSTYLE As Long = (-20)
Private Const WS_EX_RIGHT As Long = &H1000
Private Const WS_EX_LEFTSCROLLBAR As Long = &H4000
Private Const CB_SHOWDROPDOWN = &H14F
Private Enum AlignConstants
alignLeft = 0
alignright = 1
End Enum
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type COMBOBOXINFO
cbSize As Long
rcItem As RECT
rcButton As RECT
stateButton As Long
hwndCombo As Long
hwndEdit As Long
hwndList As Long
End Type
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 GetComboBoxInfo Lib "user32" _
(ByVal hwndCombo As Long, _
CBInfo As COMBOBOXINFO) As Long
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
'Private Sub ComboListAlign(cb As ComboBox, Optional ByVal Align As AlignConstants = alignLeft)
Public Sub ComboListAlign(cb As ComboBox, Optional ByVal Align As AlignConstants = alignLeft)
Dim hList As Long
Dim nStyle As Long
hList = GetComboListHandle(cb)
'if valid, change the style
If hList <> 0 Then
nStyle = GetWindowLong(hList, GWL_EXSTYLE)
Select Case Align
Case alignright
nStyle = nStyle Or WS_EX_RIGHT
Case Else
nStyle = nStyle And Not WS_EX_RIGHT
End Select
SetWindowLong hList, GWL_EXSTYLE, nStyle
End If
'drop the combo
Call SendMessage(cb.hwnd, CB_SHOWDROPDOWN, True, ByVal 0)
End Sub
Private Sub ComboScrollAlign(cb As ComboBox, Optional ByVal Align As AlignConstants = alignright)
Dim hList As Long
Dim nStyle As Long
'obtain the handle to the list
'portion of the combo
hList = GetComboListHandle(cb)
'if valid, change the style
If hList <> 0 Then
nStyle = GetWindowLong(hList, GWL_EXSTYLE)
Select Case Align
Case alignright
nStyle = nStyle Or WS_EX_LEFTSCROLLBAR
Case Else
nStyle = nStyle And Not WS_EX_LEFTSCROLLBAR
End Select
SetWindowLong hList, GWL_EXSTYLE, nStyle
End If
'drop the combo
Call SendMessage(cb.hwnd, CB_SHOWDROPDOWN, True, ByVal 0)
End Sub
Private Function GetComboListHandle(ctl As ComboBox) As Long
Dim CBI As COMBOBOXINFO
CBI.cbSize = Len(CBI)
Call GetComboBoxInfo(ctl.hwnd, CBI)
GetComboListHandle = CBI.hwndList
End Function
Dove avrò sbagliato?