Page 1 of 1
DropDown combobox color
Posted: Sat Jul 15, 2006 9:55 am
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
Posted: Sat Jul 15, 2006 12:20 pm
by Antonio Linares
Enrico,
Do you mean using FWH code ? Or in pure C ?
Posted: Sat Jul 15, 2006 12:25 pm
by Enrico Maria Giordano
Any way will be fine.
EMG
Posted: Sat Jul 15, 2006 12:33 pm
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.
Posted: Sat Jul 15, 2006 1:43 pm
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
Posted: Sat Jul 15, 2006 5:47 pm
by Antonio Linares
Enrico,
Excellent, Master
What do you use ::hBkBrush for ? -you always call CreateSolidBrush()-
Posted: Sat Jul 15, 2006 5:55 pm
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
Posted: Sat Jul 15, 2006 6:02 pm
by Antonio Linares
Enrico,
If you call CreateSolidBrush() always, then you can dinamically change the color of the control on the run.
Posted: Sat Jul 15, 2006 6:14 pm
by James Bott
Antonio,
So, are you suggesting we just do:
return CreateSolidBrush( ::nClrPane )
instead?
James
Posted: Sat Jul 15, 2006 6:26 pm
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
Posted: Sat Jul 15, 2006 6:30 pm
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
Posted: Sat Jul 15, 2006 8:23 pm
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
Posted: Sat Jul 15, 2006 9:06 pm
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