Customizable Color Picker

As a starting point, I used Luis Ortega's code from A Color Picker.

This customizable color picker was designed because I needed a color picker that could calculate itself when passed an array of colors. I didn't want to use a resource file, so the entire color dialog is created dynamically from memory. This makes using the control quick and easy. I have included methods for customizing the border sizes, number of well columns, well heights, and well shapes. The control is designed for loading colors at run-time (from a database,for example). There is not support for serialization, persistance to the registry, or an "other" button. These can be easily added if needed. My project didn't need them, so I didn't bother adding them.

A demo project is included. I hope someone else can get some use out of this code, too. :-)

How to include in your project

  1. Copy ColorBtn.cpp and ColorBtn.h into your project directory.
  2. Add ColorBtn.cpp to your project.

How to use

  1. Create a button on your dialog. Mark it as "Owner Draw".
  2. Declare a variable in your dialog class, like this:
    CColorBtn colorbtn;
  3. At OnInitDialog, call SubclassDlgItem, like this:
    colorbtn.SubclassDlgItem(IDC_BUTTON,this); // Use your button ID here
  4. Add Colors to the button's color dialog using AddColorWell or SetColorsFromArray
  5. Customize the button's color dialog by setting the number of columns, border widths, and shape variables
  6. Repeat the process for each button you want. (See the sample project provided for more details)

You can set and read the selected color using the "m_CurrentColor" member variable.

Download compiled demo app (no project files) - 81 KB

Download demo (project files) - 40 KB

Download source - 8 KB

Date Last Updated: February 3, 1999



Comments

  • cool stuff

    Posted by Legacy on 03/20/2003 12:00am

    Originally posted by: dan vallejo

    Pretty cool code

    dan@cstructor.com
    www.cstructor.com

    Reply
  • i love ariel ortega

    Posted by Legacy on 07/25/2002 12:00am

    Originally posted by: selcuk

    i love ariel ortega

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

Top White Papers and Webcasts

  • Live Event Date: May 6, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT While you likely have very good reasons for remaining on WinXP after end of support -- an estimated 20-30% of worldwide devices still are -- the bottom line is your security risk is now significant. In the absence of security patches, attackers will certainly turn their attention to this new opportunity. Join Lumension Vice President Paul Zimski in this one-hour webcast to discuss risk and, more importantly, 5 pragmatic risk mitigation techniques …

  • When it comes to desktops – physical or virtual – it's all about the applications. Cloud-hosted virtual desktops are growing fast because you get local data center-class security and 24x7 access with the complete personalization and flexibility of your own desktop. Organizations make five common mistakes when it comes to planning and implementing their application management strategy. This eBook tells you what they are and how to avoid them, and offers real-life case studies on customers who didn't let …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds