命名常用颜色






4.88/5 (15投票s)
2001年7月29日
1分钟阅读

479077

2550
一个包含文件,允许您通过名称而不是 RGB 值来指定颜色
动机
我一直对颜色选择感到困扰。我想你们也同意,Windows 定义的基本 16 种颜色很单调。但是,使用 RGB 宏并猜测 256^3 种可能性中的 R、G 和 B 值是困难的(选项太多)。即使我使用宏,也很难识别隐藏在例如 CBrush brush(RGB(210,105,30))
中的颜色。
解决方案
HTML 专家也遇到了同样的问题。为了解决这个问题,他们确定了 141 种颜色并为其分配了适当的名称。我采用了他们的定义并将其转换为头文件。如果您在代码中包含头文件 #include "ColorNames.h"
,您将能够使用 HTML 颜色名称代替 RGB 宏,例如 CBrush brush(colChocolate)
。
我发现这样使用和记忆更容易。希望对您也有帮助。
下面是“ColorNames.h”文件的一部分,您所需要的全部就是这个文件。演示应用程序将向您展示所有 141 种颜色及其名称。
//
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);
//
许可证
本文未附加明确的许可证,但可能在文章文本或下载文件本身中包含使用条款。如有疑问,请通过下面的讨论区联系作者。
作者可能使用的许可证列表可以在此处找到。