Cool Color Selector Including Hue, Saturation, and Lumination

Environment: VC6, VC7.NET, WinXP, Win2000, Win98, NT4 SP3

When I created this color selector, I was creating a 3D graphics program. I was using the standard Windows common color selection dialog box. However, it became a bit tedious selecting the "Define Custom Colors >>" button to select custom colors. So, I designed this color selector. I find it much easier to use. All color boxes can be dragged and dropped onto the custom color boxes. Custom color values are automatically restored each time the dialog box is displayed. The colors can all be dragged onto the "New Color:" box to select that color.

Clicking on the "Current Color:" color box will select the original color again. However, it is not possible (without modifications) to drag a color on top of the "Current Color:" color box because that would defeat the object of having it.

It is possible to change the color reference, hue value, saturation value, lumination value, red value, green value, and the blue value.

I hope that this is of some use to you.

// declare a variable to store our color
COLORREF rgbColor = RGB(255, 0, 0);

// create an instance of the color selector
CSelColorDlg dlgSelColor(GetRValue(rgbColor),
             GetGValue(rgbColor),
             GetBValue(rgbColor));

// display the color changing dialog box
if(dlgSelColor.DoModal() == IDOK)
{
  // select the new color
  rgbColor = dlgSelColor.GetColor();
  // change the background color
  Invalidate();
}

Downloads

Download demo project - 52 Kb
Download source - 10 Kb


About the Author

Lea Hayes

I have always enjoyed learning new concepts which is one of the things which suits me to programming, because in programming you are always learning new and interesting concepts. I have been programming since about 1995 and have become reasonably experienced with Microsoft Visual Basic 4,5,6 and Microsoft Visual C++ 5,6,7,7.1. Having achieved a double A grade in AVCE ICT I have begun to study BEng Games and Entertainment Systems Engineering at the University of Greenwich at Medway. I have now completed my first year with the kind of results expected from a first-class degree.

Comments

  • good stuff

    Posted by Legacy on 08/29/2003 12:00am

    Originally posted by: Pavele

    Good stuff ! Compiles with some warnings on VC7, but they is not difficult to solve. May be a button "Add to custom colors" is still needed. Drag and drop operations are not obvious to the user. Anyhow, thanks, mate !

    Reply
  • Not about the Author. Brian You are a moron!

    Posted by Legacy on 08/26/2003 12:00am

    Originally posted by: Brian is a moron

    This message is directed toward the first comment. The author is right and you are a moron Brian!

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

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • Some of the statistics about the growth of enterprise mobility are surprising, not the least of which is the 4X increase in mobile malware from 2013 to 2014. Many employees today not only expect to be able to use their own personal devices at work, but will even contravene policies that restrict personal device use for work.  IT must find the right approach that balances the benefits of mobility with the risks involved.  This on-demand webcast offers steps toward developing a winning mobile strategy, and …

Most Popular Programming Stories

More for Developers

RSS Feeds