COLORREF,COLOR,RGB,CString的转化总结分析

  int iRed = GetRValue(pMarkInfo->lfColor);

  int iGreen = GetGValue(pMarkInfo->lfColor);

  int iBlue = GetBValue(pMarkInfo->lfColor);

  CString szColor;

  szColor.Format(_T("#%02X%02X%02X"), iRed, iGreen, iBlue);

  /////////////////////////////////////////////////////

  CString m_BackColor.m_frame_color = "#0290D8";

  DWORD r,g,b;

  sscanf(m_BackColor.m_frame_color,"#%2X%2X%2X",&r,&g,&b);

  COLORREF rgb = RGB(r,g,b);

  brush.CreateSolidBrush (rgb)

  //////////////////////////////////////////////////

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

  }

  ///////////////////////////////////////////////////////