int CWorkSpace::GetColorRGB(std::string strColorText, COLORREF& color)
{
char chR[4] = {0}, chG[4] = {0}, chB[4] = {0};
sscanf(strColorText.c_str(), "%[^,],%[^,],%[^,]", chR, chG, chB);
color = RGB(atoi(chR), atoi(chG), atoi(chB));
return 0;
}
本文介绍了一个C++函数,该函数能够从字符串中解析出RGB颜色值并转换为COLORREF类型。通过使用sscanf进行分隔符读取,并利用atoi将字符型的RGB值转换成整数。
int CWorkSpace::GetColorRGB(std::string strColorText, COLORREF& color)
{
char chR[4] = {0}, chG[4] = {0}, chB[4] = {0};
sscanf(strColorText.c_str(), "%[^,],%[^,],%[^,]", chR, chG, chB);
color = RGB(atoi(chR), atoi(chG), atoi(chB));
return 0;
}

被折叠的 条评论
为什么被折叠?