当前位置: 首页 > 编程语言 > C++ > 正文

HTML颜色格式#FFFFFF转换为COLORREF方法

时间:2015-05-21

老土的方式:

szColor.Replace("#", "");  
            int iArrColor[6] = {0};  
            TCHAR hexSeed[] = _T("0123456789ABCDEF");  
            for (int i = 0; i < 6; i++){  
                TCHAR tcByte = szColor.GetAt(i);  
                for (int j=0; j < 16; j++){  
                    if (tcByte == hexSeed[j]){  
                        iArrColor[i] = j;  
                    }  
                }  
            }  
                  
      
            COLORREF rgbColor = RGB(iArrColor[0] * 16 + iArrColor[1], iArrColor[2] * 16 + iArrColor[3], iArrColor[4] * 16 + iArrColor[5]);

新思路:

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)

作者:csdn博客 微wx笑

返回栏目页:http://www.bianceng.cn/Programming/cplus/