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

Naming Common Colors

0.00/5 (No votes)
28 Jul 2001 3  
An include file that allows you to specify colors by name instead of RGB value

Sample Image - ColorNames.gif

Motivation

I always have serious problems when it comes to the point of color selection. I guess you'll agree that basic 16 colors that windows define are boring. However, using RGB macro and guessing R,G and B values out of 256^3 possibilities is problematic (too many options). Even if I use the macro, I can hardly recognize which color is hiding behind say CBrush brush(RGB(210,105,30)).

Solution

HTML gurus experienced the same problem. To solve it, they identified 141 colors and assign them appropriate names. I took their definition and convert it into a header file. If you include the header #include "ColorNames.h" into your code, you will be able to use HTML color names instead of the RGB macro, say CBrush brush(colChocolate).

I find this easier to use and to remember. I hope it will help you, too.

Below is a part of the "ColorNames.h" file and this file is all you need. The demo application will present you all 141 colors and their names.

//
const COLORREF colAliceBlue            = RGB(240,248,255);
const COLORREF colAntiqueWhite         = RGB(250,235,215);
const COLORREF colAqua                 = RGB(  0,255,255);
const COLORREF colAquamarine           = RGB(127,255,212); 
const COLORREF colAzure                = RGB(240,255,255);
const COLORREF colBeige                = RGB(245,245,220);
const COLORREF colBisque               = RGB(255,228,196);
const COLORREF colBlack                = RGB(  0,  0,  0);
const COLORREF colBlanchedAlmond       = RGB(255,255,205);
const COLORREF colBlue                 = RGB(  0,  0,255);
const COLORREF colBlueViolet           = RGB(138, 43,226);
const COLORREF colBrown                = RGB(165, 42, 42);
const COLORREF colBurlywood            = RGB(222,184,135);
const COLORREF colCadetBlue            = RGB( 95,158,160);
const COLORREF colChartreuse           = RGB(127,255,  0);
const COLORREF colChocolate            = RGB(210,105, 30);
const COLORREF colCoral                = RGB(255,127, 80);
const COLORREF colCornflowerBlue       = RGB(100,149,237);
const COLORREF colCornsilk             = RGB(255,248,220);
const COLORREF colCrimson              = RGB(220, 20, 60);
const COLORREF colCyan                 = RGB(  0,255,255);
//

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.

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