DropDown combobox color

Post Reply
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

DropDown combobox color

Post by Enrico Maria Giordano »

Dear friends, any idea on how to change the foreground and background colors of a standard CBS_DROPDOWN (the one in which you can write) combobox (not the FWH one with a TGet on it)?

EMG
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Enrico,

Do you mean using FWH code ? Or in pure C ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Enrico,

Have a look to WM_CTLCOLORLISTBOX. It should be similar for a ComboBox.

Also, you have to consider that there is an Edit control (TGet in FWH) as a child of the combobox, so the combobox also has to answer to WM_CTLCOLORLISTBOX.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

Thanks to your idea I solved my problem this way:

Code: Select all

METHOD CtlColor( hWndChild, hDCChild ) CLASS TComboBox

   if lAnd( GetWindowLong( ::hWnd, GWL_STYLE ), CBS_DROPDOWN )
      SetTextColor( hDCChild, ::nClrText )
      SetBkColor( hDCChild, ::nClrPane )

      ::hBkBrush = CreateSolidBrush( ::nClrPane )

      return ::hBkBrush
   endif

return nil
EMG
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Enrico,

Excellent, Master :)

What do you use ::hBkBrush for ? -you always call CreateSolidBrush()-
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

Antonio Linares wrote:Enrico,

Excellent, Master :)

What do you use ::hBkBrush for ? -you always call CreateSolidBrush()-
You are right! I have to call it only once, maybe inside Default() method (I already release it inside Destroy() method).

Thank you for pointed it out!

EMG
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Enrico,

If you call CreateSolidBrush() always, then you can dinamically change the color of the control on the run.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Antonio,

So, are you suggesting we just do:

return CreateSolidBrush( ::nClrPane )

instead?

James
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

Antonio Linares wrote:Enrico,

If you call CreateSolidBrush() always, then you can dinamically change the color of the control on the run.
Yes. But at the moment I don't need of this feature.

EMG
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

James Bott wrote:Antonio,

So, are you suggesting we just do:

return CreateSolidBrush( ::nClrPane )

instead?

James
Almost. But that way you can't release the brush and this will cause a resource leakage. You need to store the handle and release it before create the new brush. And release it once more when the control is destroyed.

EMG
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Enrico,

Thanks for the explaination. This feature would be very useful if you wish to color the background different for required fields, then change it to white if the data is entered and vaild. You may remember me discussing this before.

James
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

Yes, but please notice that you can already do this with FWH dropdown comboboxes as they have a TGet on them. My coloring problem was about standard Windows dropdown comboboxes.

EMG
Post Reply