Click here to Skip to main content
15,867,488 members
Articles / Desktop Programming / ATL

Naming Common Colors

Rate me:
Please Sign up or sign in to vote.
4.88/5 (17 votes)
28 Jul 20011 min read 474.2K   2.5K   28   9
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.

C++
//
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.


Written By
Web Developer
Slovenia Slovenia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionWrong color codes Pin
Phagos5-Sep-19 12:19
Phagos5-Sep-19 12:19 
GeneralNice project, but here is a change... Pin
17-Oct-01 13:32
suss17-Oct-01 13:32 
GeneralRe: Nice project, but here is a change... Pin
Ales Krajnc17-Oct-01 21:01
Ales Krajnc17-Oct-01 21:01 
GeneralSee CColor Pin
1-Aug-01 2:43
suss1-Aug-01 2:43 
Generalcopyright disclaimer Pin
30-Jul-01 13:16
suss30-Jul-01 13:16 
I suggest putting the X Consortium copyright disclaimer in the header, like emacs does in its rgb.txt.
General[Message Deleted] Pin
rtortora30-Jul-01 5:59
rtortora30-Jul-01 5:59 
GeneralRe: Color-picker programs Pin
Alexander Berthold1-Aug-01 4:09
Alexander Berthold1-Aug-01 4:09 
GeneralWeb-safe colors Pin
30-Jul-01 1:41
suss30-Jul-01 1:41 
QuestionWhat a good idea! Pin
29-Jul-01 15:30
suss29-Jul-01 15:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.