Combobox Color Picker 3

.
(Based On Earlier Code That Was By Baldvin Hansson.)

This class, CColorPickerCB, implements a Combobox that displays colors, as well as the name of the colors. Colors may be added or removed at runtime, and the control can be queried for the COLORREF value, or the name of the selected color. You can also set the selected color.

The control correctly handles selection, enabled and disabled drawing (see images below of the control is various states). Since the control uses strings for display, the colors can be sorted.

CColorPickerCB Sample Images

To use this control, create a Drop List Combobox with the "Owner Draw Fixed" and "Has Strings" styles. Attach a CColorPickerCB to the control, and off you go!

Note that the control will use 1/4 (one fourth) of its width for the color block, and the rest, minus a few pixels, for the color text. Be sure you make it wide enough.

If you want the source code to make sense, be sure you are set to a Tab size of 4, or the comments and code will not line up correctly.

Any questions or comments, please do not hesitate to EMail me.

 

Thanx to Marcel Galema for finding a bug with my inverted (selected) color usage, and suggesting a fix for it.

 

Here is a list of public functions in the CColorPickerCB class:

COLORREF GetSelectedColorValue(void)           // Get Selected Color Value
CString GetSelectedColorName(void);            // Get Selected Color Name
void SetSelectedColorValue(COLORREF crColor)   // Set Selected Color Value
void SetSelectedColorName(PCSTR cpColor);      // Set Selected Color Name
bool RemoveColor(PCSTR cpColor);               // Remove Color From List
bool RemoveColor(COLORREF crColor);            // Remove Color From List
int  AddColor(PCSTR cpName, COLORREF crColor); // Insert A New Color

The sample application can be obtained here, and the code for the CColorPickerCB class can be obtained here.

)1998 James R. Twine

Last Update: August 25, 1998



Comments

  • combo color in vb

    Posted by Legacy on 02/02/2004 12:00am

    Originally posted by: Ferdz

    could you share a sample written in vb.net? very urgent only. thanks! i'll appreciate whatever responce you may have.

    Reply
  • Color Picker Combo Box (3)

    Posted by Legacy on 11/20/1998 12:00am

    Originally posted by: Michael

    If you want use your source code in SDI or MDI you had to remove all
    
    references of BOOL m_bInitialized.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: September 17, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Another day, another end-of-support deadline. You've heard enough about the hazards of not migrating to Windows Server 2008 or 2012. What you may not know is that there's plenty in it for you and your business, like increased automation and performance, time-saving technical features, and a lower total cost of ownership. Check out this upcoming eSeminar and join Rich Holmes, Pomeroy's practice director of virtualization, as he discusses the …

  • Live Event Date: September 10, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild". This loop of continuous delivery and continuous feedback is …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds