DropDown combobox color

DropDown combobox color

Postby Enrico Maria Giordano » Sat Jul 15, 2006 9: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
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Enrico Maria Giordano » Sat Jul 15, 2006 12:25 pm

Any way will be fine.

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

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Enrico Maria Giordano » Sat Jul 15, 2006 1:43 pm

Thanks to your idea I solved my problem this way:

Code: Select all  Expand view
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
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Antonio Linares » Sat Jul 15, 2006 5:47 pm

Enrico,

Excellent, Master :)

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

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

Postby Enrico Maria Giordano » Sat Jul 15, 2006 5: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
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Antonio Linares » Sat Jul 15, 2006 6: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby James Bott » Sat Jul 15, 2006 6:14 pm

Antonio,

So, are you suggesting we just do:

return CreateSolidBrush( ::nClrPane )

instead?

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

Postby Enrico Maria Giordano » Sat Jul 15, 2006 6: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
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Enrico Maria Giordano » Sat Jul 15, 2006 6: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
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby James Bott » Sat Jul 15, 2006 8: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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Enrico Maria Giordano » Sat Jul 15, 2006 9: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
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 88 guests