一、COLORREF与RGB的相互转化
RGB(r,g,b)是一个宏
实际上它做得事是((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(,,);
第二种
    if( colorDialog.DoModal() == IDOK )
    {
        color = colorDialog.GetColor();
    }
如何从 COLORREF中取出RGB分量值?
可以使用宏GetRValue
 GetGValue
 GetBValue
他们的定义如下
#define GetRValue(rgb)      ((BYTE)(rgb))
#define GetGValue(rgb)      ((BYTE)(((WORD)(rgb)) >> 8))
#define GetBValue(rgb) ((BYTE)((rgb)>>16))
二 、Color与ColorRef(int类型表示的颜色)的相互转换
实际的软件开发过程中,常需要用到非.net平台的代码。这时候就可能碰到ColorRef(也就是以int类型代表的颜色值或是以DWORD值表示的颜色)。这跟.net平台下的颜色的相互转换MS并没有直接实现。那么就需要我们自己处理了。这里给出两个函数。 
Color GetArgbColor(int color)        
 {            
     int blue = color & 255;            
     int green = color >> 8 & 255;            
     int red = color >> 16 & 255 ;            
     return Color.FromArgb(blue, green, red);        
 } 
三、 注意
}
////////////////////////////////////////////////////////////////////
COLORREF 和字符之间的转换
一、格式化字符串的功能很强大
BOOL CDataManager::GetRGBText(std::string &strRGBText , COLORREF color)
{
 //COLORREF col = RGB( 255 , 12 , 4);
 BYTE Red = GetRValue(color); ///得到红颜色
 BYTE Green = GetGValue(color); ///得到绿颜色
 BYTE Blue = GetBValue(color); ///得到兰颜色
 char chR[4];
 itoa(Red ,chR , 10 );
 char chG[4];
 itoa(Green , chG , 10);
 char chB[4];
 itoa(Blue , chB , 10);
 std::string strR , strG, strB;
 strR = chR ;
 strG = chG;
 strB = chB;
strRGBText = strR + "," + strG + "," + strB;
 return TRUE;
}
//字符串转换为COLORREF,如("32","34","21")
BOOL CDataManager::GetColorRGB(CString strColorText , COLORREF& color)
{
    char chR[4] = "", chG[4] = "", chB[4] = ""; 
    sscanf( strColorText, "%[^,],%[^,],%[^,]", chR, chG, chB);
 color = RGB(atoi(chR), atoi(chG), atoi(chB));
 return TRUE;
}
///////////////////////////////////////////////////////