Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Cool Colour Selector Including Hue, Saturation, and Lumination

0.00/5 (No votes)
9 Nov 2006 1  
This colour selector helps to make selecting colours more efficient

Introduction

When I created this colour selector I was creating a 3D graphics program; I was using the standard windows common colour selection dialog box however it became a bit tedious selecting the "Define Custom Colours >>" button to select custom colours. So I designed this colour selector which I find much easier to use.

Using the code

All colour boxes can be dragged and dropped onto the custom colour boxes. Custom colour values are automatically restored each time the dialog box is displayed. The colours can all be dragged onto the "New Colour:" box to select that colour.

Clicking on the "Current Colour:" colour box will select the original colour again. However it is not possible (without modifications) to drag a colour on-top of the "Current Colour:" colour box as that would defeat the object of having it.

It is possible to change the colour 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();
}

Points of Interest

Most of the visual appearance of the colour selector has relied on the use of GetBitmapBits() and SetBitmapBits() to save on processing time. When the colour images are generated the image is stored within a CBitmap object; then later to be drawn as usual.

History

  • Fixed major bug regarding desktop colour depths.

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