FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour DropDown combobox color
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
DropDown combobox color
Posted: Sat Jul 15, 2006 09:55 AM

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

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
DropDown combobox color
Posted: Sat Jul 15, 2006 12:20 PM

Enrico,

Do you mean using FWH code ? Or in pure C ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
DropDown combobox color
Posted: Sat Jul 15, 2006 12:25 PM

Any way will be fine.

EMG

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
DropDown combobox color
Posted: Sat Jul 15, 2006 12:33 PM

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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
DropDown combobox color
Posted: Sat Jul 15, 2006 01:43 PM
Thanks to your idea I solved my problem this way:

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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
DropDown combobox color
Posted: Sat Jul 15, 2006 05:47 PM

Enrico,

Excellent, Master :)

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

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
DropDown combobox color
Posted: Sat Jul 15, 2006 05:55 PM
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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
DropDown combobox color
Posted: Sat Jul 15, 2006 06:02 PM

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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
DropDown combobox color
Posted: Sat Jul 15, 2006 06:14 PM

Antonio,

So, are you suggesting we just do:

return CreateSolidBrush( ::nClrPane )

instead?

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
DropDown combobox color
Posted: Sat Jul 15, 2006 06:26 PM
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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
DropDown combobox color
Posted: Sat Jul 15, 2006 06:30 PM
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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
DropDown combobox color
Posted: Sat Jul 15, 2006 08:23 PM

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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
DropDown combobox color
Posted: Sat Jul 15, 2006 09:06 PM

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

Continue the discussion