Hallo icolor!
Ich habe eine Lösung gefunden - allerdings nicht ohne Subclassing. Subclassen muss man dabei nicht die Form oder die ComboBox, sondern die interne ListBox der ComboBox.
Folgender Code in ein Modul:Option Explicit
'combobox
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
hwndItem As Long
hwndList As Long
End Type
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal _
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) _
As Long
Private Const CB_GETCOMBOBOXINFO As Long = &H164& 'wParam: not used; lParam:
' pointer to COMBOBOXINFO
'subclassing
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( _
ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_WNDPROC = (-4)
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" ( _
ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal _
wParam As Long, ByVal lParam As Long) As Long
'listbox
Private Const WM_WINDOWPOSCHANGING = &H46
Private Type WINDOWPOS
hwnd As Long
hWndInsertAfter As Long
x As Long
y As Long
cx As Long
cy As Long
flags As Long
End Type
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
Destination As Any, Source As Any, ByVal Length As Long)
'variables
Private lngWndProc As Long
Private hwndComboList As Long
Private lngDiff As Long
Public Sub StartComboboxListLeft(ByVal hwndCombobox As Long, ByVal _
lngDifference As Long)
Dim cbi As COMBOBOXINFO
cbi.cbSize = Len(cbi)
SendMessage hwndCombobox, CB_GETCOMBOBOXINFO, 0&, cbi
hwndComboList = cbi.hwndList
lngWndProc = SetWindowLong(hwndComboList, GWL_WNDPROC, AddressOf _
ComboboxListLeftWndProc)
lngDiff = lngDifference
End Sub
Public Sub StopComboboxListLeft()
If lngWndProc <> 0 And hwndComboList <> 0 Then SetWindowLong _
hwndComboList, GWL_WNDPROC, lngWndProc
End Sub
Public Function ComboboxListLeftWndProc(ByVal hwnd As Long, ByVal Msg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Dim wp As WINDOWPOS
If Msg = WM_WINDOWPOSCHANGING Then
CopyMemory wp, ByVal lParam, Len(wp)
wp.x = wp.x + lngDiff
wp.cx = wp.cx - lngDiff
CopyMemory ByVal lParam, wp, Len(wp)
End If
ComboboxListLeftWndProc = CallWindowProc(lngWndProc, hwnd, Msg, wParam, lParam)
End Function Das Ganze wird dann im Form_Load aufgerufen:StartComboboxListLeft Combo1.hwnd, -20 Der zweite Parameter ist dabei die Differenz, um die die ComboBox versetzt aufgeklappt wird; in diesem Fall ein negativer Wert, um die Liste nach links zu verschieben.
Wichtig ist natürlich, am Ende das Subclassing wieder zu beenden, daher unbedingt:Private Sub Form_Unload(Cancel As Integer)
StopComboboxListLeft
End Sub Zu beachten sind natürlich die üblichen Regeln des Subclassings, also kein Debugging, Programm in der IDE NIEMALS mit dem Stop-Button beenden, und natürlich immer Speichern vor der Programmausführung in der IDE, usw.
Außerdem funtioniert das Ganze natürlich nur für eine einzige ComboBox; wenn man diese Funktion für mehrere ComboBoxen haben will, muss man die Funktionen entsprechend anpassen.
mfg mst547 |