Click here to Skip to main content
6,292,811 members and growing! (10,195 online)
Email Password   helpLost your password?
Desktop Development » Combo & List Boxes » ComboBox Controls     Intermediate

Color Picker Combo Box

By James R. Twine

A combobox derived class that provides a simple color picker
VC6, MFC, Dev
Posted:16 Jan 2000
Updated:18 Oct 2000
Views:161,248
Bookmarked:38 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
21 votes for this article.
Popularity: 5.50 Rating: 4.16 out of 5

1
1 vote, 11.1%
2
1 vote, 11.1%
3
2 votes, 22.2%
4
5 votes, 55.6%
5
  • Download demo project (James Twine's version) - 26 Kb
  • Download source files (James Twine's version) - 8 Kb


  • Download demo project (Mark Jackson's version) - 18 Kb
  • Download source files (Mark Jackson's version) - 2 Kb
  • Sample Image - ColourPickerCB.gif

    Introduction

    James Twine originally based this code on earlier work by Baldvin Hansson. Mark Jackson (www.mjsoft.co.uk) has expanded this to add a "Custom..." option at the bottom of the list which displays the standard colour picker dialog, and has also added DDX data exchange. The code has also been improved and tidied up in many other ways.

    The CColorPickerCB class 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. Since the control uses strings for display, the colors can be sorted.

    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!

    The initialization routine populates the color picker with a color selection that is a subset of the X11 colorset, and are the colors that are recognized by IE.

    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.

    Credits

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

    Thanks also to Paul Wardle for providing DDX routines.

    Public Functions

    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
    
    
    // Initialize The Control With The Default Colorset
    
    void InitializeDefaultColors( void );          
    
    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
    
    

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    James R. Twine


    Member
    Programming since the age of 10, started professionally at the age of 17. Currently involved in both Client and Server side development on Win32 platforms for MC/HA/FT financial applications. Development experience with Win32, Win16, Linux and other flavors of Unix.

    Extensive multithreaded development experience on Windows platforms using the Win32 SDK, and MFC.

    Experience with HA/FT n-tiered Client/Server systems as well as GUI apps of varying complexity. Some experience with Game developement.

    Having learned that the stuff you can barely get away with doing Client-side apps just does not cut it in the real "Server World", I am amazed how many 'professionals' cannot tell the difference between "works" and "correct" or try to (mis)use VB and/or MFC on server-side development projects, never considering that just because it RUNS, does not mean it runs WELL.

    Lastly, I am also a collector of arcade games, and can perform repairs, conversions, etc. Search for my name, you will find me on lots of arcade-related documents and sites.

    Sites of interest(?):
    http://www.jrtwine.com
    http://www.jrtwine.com/jtwine
    http://www.signingtime.com
    http://www.deletefxpfiles.com
    http://www.checkfavorites.com
    http://www.coinop.org
    Occupation: President
    Company: JRTwine Software, LLC
    Location: United States United States

    Other popular Combo & List Boxes articles:

    Article Top
    You must Sign In to use this message board.
    FAQ FAQ 
     
    Noise Tolerance  Layout  Per page   
     Msgs 1 to 25 of 38 (Total in Forum: 38) (Refresh)FirstPrevNext
    GeneralInitializing dropbox Pinmemberal250016:01 22 Jul '07  
    QuestionAsserttion failed! Pinmemberjrmd3:37 14 Jan '07  
    AnswerRe: Asserttion failed! PinmemberJames R. Twine8:13 14 Jan '07  
    GeneralRe: Asserttion failed! Pinmemberjrmd3:22 15 Jan '07  
    GeneralDoubt Pinmembersruti_p22:11 13 Jun '06  
    AnswerFirst Steps... (Was: Re: Doubt) PinmemberJames R. Twine2:13 14 Jun '06  
    QuestionChanging the Font Pinmemberpscholl23:17 10 May '06  
    AnswerRe: Changing the Font PinmemberJames R. Twine2:15 14 Jun '06  
    AnswerRe: Changing the Font Pinmemberpscholl6:02 27 Feb '07  
    GeneralDebug assertion failed Pinmemberleft1none0:22 7 Feb '06  
    AnswerRe: Debug assertion failed PinmemberJames R. Twine2:16 14 Jun '06  
    GeneralRe: Debug assertion failed Pinmembershvalbo3:22 14 Dec '06  
    GeneralOwner draw combobox with CBS_DROPDOWN style PinmemberG.A.0:18 15 Dec '04  
    GeneralRe: Owner draw combobox with CBS_DROPDOWN style PinmemberJames R. Twine2:18 14 Jun '06  
    AnswerRe: Owner draw combobox with CBS_DROPDOWN style PinmemberMember 42633021:12 19 May '09  
    GeneralHow can I use a CComboBox as a Lenght specifier? PinmemberTimawa_6922:00 20 Apr '04  
    GeneralRe: How can I use a CComboBox as a Lenght specifier? PinmemberJames R. Twine15:19 26 Apr '04  
    GeneralCan this combo box be made FLAT Pinmembermangeshb12319:48 16 Oct '03  
    GeneralRe: Can this combo box be made FLAT PinmemberJames R. Twine4:30 17 Oct '03  
    GeneralHow to initialize with my own colors? I'd add few methods.. Pinsussandru1231:16 6 Nov '02  
    GeneralRe: How to initialize with my own colors? I'd add few methods.. PinmemberJames R. Twine7:58 8 Aug '03  
    GeneralHow to Create a ComboBox in toolbar? Pinmemberwhite jungle4:27 16 Nov '01  
    GeneralRe: How to Create a ComboBox in toolbar? PinmemberCarlos Antollini4:50 16 Nov '01  
    GeneralRe: How to Create a ComboBox in toolbar? Pinmembertvhead8018:32 21 Mar '03  
    GeneralRe: How to Create a ComboBox in toolbar? Pinmemberleft1none0:10 7 Feb '06  

    General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    PermaLink | Privacy | Terms of Use
    Last Updated: 18 Oct 2000
    Editor: Nishant Sivakumar
    Copyright 2000 by James R. Twine
    Everything else Copyright © CodeProject, 1999-2009
    Web12 | Advertise on the Code Project