Results 1 to 5 of 5

Thread: Set background & text color of a image combo box dropdown list

  1. #1

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Question 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.

  2. #2
    Addicted Member
    Join Date
    Jun 2009
    Location
    C:\Windows\SysWOW64\
    Posts
    229

    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.

  3. #3
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,654

    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.

  4. #4
    Addicted Member
    Join Date
    Jun 2009
    Location
    C:\Windows\SysWOW64\
    Posts
    229

    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?

  5. #5
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,654

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width