Click here to Skip to main content
15,742,764 members
Articles / Desktop Programming / ATL
Posted 28 Jul 2001


27 bookmarked

Naming Common Colors

Rate me:
Please Sign up or sign in to vote.
4.88/5 (17 votes)
28 Jul 20011 min read
An include file that allows you to specify colors by name instead of RGB value

Sample Image - ColorNames.gif


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)).


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);


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 
I like this project a lot! But the text color did not show up very well on my screen, so I changed the test code that draws black or white text to key on the tatal value of the RGB values. This works much better for me. Then I thought that it would be nice to actually know what the RGB values are, so I changed the string that gets drawn on top of the color to include them. The replacement for the OnDraw method is included in its entirety below. Simply copy this one and paste it over the old one to see the changes.

body { margin-left: 2%; margin_right: 2%; }
t1 { padding-left: 5%; }
t2 { margin-left: 10%; }

void CNamedColorsView::OnDraw(CDC* pDC)
   CNamedColorsDoc* pDoc = GetDocument();

   const int iCols = 5;
   const int iNumCol = sizeof(m_arCN)/sizeof(CN);

   CRect rcView;
   CSize szGrid(rcView.Width()/iCols, rcView.Height()/((iNumCol/iCols)+1));
   CSize szItem(*0.9,*0.9);

   int iSavedDC = pDC->SaveDC();

   CPen pen(PS_NULL, 0, RGB(0,0,0));
   pDC->SetTextAlign(TA_CENTER | TA_BOTTOM);

   for(int i=0; i < iNumCol; i++)
<t2>      CRect rc(CPoint(i%iCols*, i/iCols*, szItem);

      COLORREF cr = m_arCN[i].m_color;
      int totalColor = GetRValue(cr) + GetGValue(cr) + GetBValue(cr);

      CString str;
      str.Format("%s (%d,%d,%d)", m_arCN[i].m_pcName,
            GetRValue(cr), GetGValue(cr), GetBValue(cr));

      CBrush brush(cr);

      pDC->SetTextColor(totalColor < 250 ? colWhite : colBlack);
      pDC->TextOut(rc.CenterPoint().x, rc.bottom-3, str);


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 
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.