Win32 COLORREF、RGB、获取颜色分量

COLORREF 是一个 32-bit 整型数值,它代表了一种颜色。
COLORREF 值用于指定 RGB 颜色。

可以用RGB宏来初始化一个COLORREF 值;
也可以直接赋予一个十六进制值;
也可以把颜色对话框的返回值赋给一个COLORREF类型变量;


使用 GetRValue、 GetGValue 和 GetBValue 宏获取颜色分量;

void CColortest1View::OnDraw(CDC* pDC)
{
	CColortest1Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	CString str1;

	COLORREF color=RGB(120,255,60);
	BYTE r = GetRValue(color);
	BYTE g = GetGValue(color);
	BYTE b = GetBValue(color);

	str1.Format("%d", color);
	pDC->TextOut(20,20,str1);
	str1.Format("%d", r);
	pDC->TextOut(20,50,str1);
	str1.Format("%d", g);
	pDC->TextOut(70,50,str1);
	str1.Format("%d", b);
	pDC->TextOut(120,50,str1);

	COLORREF color2 =  0x001133FF;
	BYTE r2 = GetRValue(color2);
	BYTE g2 = GetGValue(color2);
	BYTE b2 = GetBValue(color2);

	str1.Format("%d", 

你可能感兴趣的:(VC++,RGB,颜色分量)