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

More by Author

Previous article
Next article

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read