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

老土的方式:

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)




你可能感兴趣的:(HTML颜色格式#FFFFFF转换为COLORREF方法)