RGB(r,g,b)是一个宏
实际上它做得事是((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16)))
实际上它做得事是((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16)))
rgb(r,g,b) = 一个整型值 = r + g * 256 + b*255*256
COLORREF 是 一 个 32-bit 整 型 数 值,它 代 表 了一 种 颜 色。你 可以 使 用 RGB 函 数 来 初始化 COLORREF
它的定义
typedef DWORD COLORREF;
COLORREF变量有两种赋值方法
第一种
COLORREF cf = RGB(,,);
COLORREF cf = RGB(,,);
第二种
CColorDialog colorDialog;
COLORREF color;
CColorDialog colorDialog;
COLORREF color;
if( colorDialog.DoModal() == IDOK )
{
color = colorDialog.GetColor();
}
{
color = colorDialog.GetColor();
}
这 段 代 码 使 用 了 MFC 中 的 颜 色 对 话 框
如何从 COLORREF中取出RGB分量值?可以使用宏
GetRValue
GetGValue
GetBValue
GetGValue
GetBValue
他们的定义如下
#define GetRValue(rgb) ((BYTE)(rgb))
#define GetGValue(rgb) ((BYTE)(((WORD)(rgb)) >> 8))
#define GetBValue(rgb) ((BYTE)((rgb)>>16))