Set background & text color of a image combo box dropdown list
VB6SP6, VBCCR17, Win10 (latest)
I subclassed a ImageCombo from Krool's Common Controls Replacement to change the background color and text color of the DropDownList.
Unfortunately, the APIs don't affect the background color and text color.
Can someone check my subclass code?
Code:
Public Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Public Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Const OPAQUE = 2
Const TRANSPARENT = 1
Dim hBrush As Long
Private Function ISubclass_WindowProc(ByVal hWnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If hWnd = ImageCombo1.hWnd Then
If iMsg = WM_CTLCOLORLISTBOX Then
'https://learn.microsoft.com/en-us/windows/win32/controls/wm-ctlcolorlistbox
' wParam = Handle to the device context for the list box.
' lParam = Handle to the list box.
If lParam = ImageCombo1.hWndList Then
SetBkMode wParam, OPAQUE
SetBkColor wParam, vbBlack
SetTextColor wParam, vbWhite
hBrush = CreateSolidBrush(vbBlack) 'list background color
ISubclass_WindowProc = hBrush ' return background color
End If
End If
End If
End Function
Leider haben die APIs keine Auswirkungen auf den Hintergrund und Textfarbe.
Re: Set background & text color of a image combo box dropdown list
I have the exact same problem, also with Krool's Common Controls.
I want to set back & fore colors but I can't make it work. I have also tried subclassing but to no avail.
In standard (Krool's) combobox it works fine.
The only difference in my code is that I have the brush in a module variable and call DestroyObject on unload.
Re: Set background & text color of a image combo box dropdown list
Different hwnds make up a combo box... an additional in the case of ComboBoxEx, the control ImageCombo wraps. Try sending CBEM_GETCOMBOCONTROL to ImageCombo1.hWnd to get the underlying combo, then subclass that. If that doesn't work you may need to go further and call GetComboBoxInfo on the underlying combo to get the hwnd of its ListBox.
Re: Set background & text color of a image combo box dropdown list
I'm using hWndCombo property, which is essentially taken from CBEM_GETCOMBOCONTROL by the control.
I see you also had the same problem a while ago: https://www.vbforums.com/showthread....Combo)-control
I assume you haven't found a solution?
Re: Set background & text color of a image combo box dropdown list
I remember that now. Yeah I tried a long, long list of things and nothing worked. Tried a few more now I thought I might have missed, still no luck. One possibility I haven't deeply explored is going through the theming APIs.