CBrush Brush, *pOldBrush;
Brush.CreateSolidBrush(HS_BDIAGONAL, RGB(255, 0, 0));
pOldBrush = pDC ->SelectObject(&Brush);
上面代码的本意是创建画刷,选入设备上下文;遗憾,在创建画刷时错了,参数的个数出了问题,这里和创建画笔不同,创建画笔时要定义三个参数:格式,宽度,颜色;而创建画刷只需定义颜色。
创建画刷,并对其进行自定义
代码
CRect rect;
GetClientRect(rect);
pDC ->SetMapMode(MM_ANISOTROPIC);
pDC ->SetWindowExt(rect.Width(), rect.Height());
pDC ->SetViewportExt(rect.Width()/2, -rect.Height()/2);
pDC ->SetViewportOrg(rect.Width()/2, rect.Height()/2);
rect.OffsetRect(-rect.Width()/2, -rect.Height()/2);
CRect rect1(CPoint(-100, 50), CPoint(100, 100));
CRect rect2(CPoint(-100, -100), CPoint(100, -50));
CBrush Brush(HS_BDIAGONAL,RGB(255, 0, 0));
CBrush *pOldBrush = pDC ->SelectObject(&Brush);
pDC ->FillRect(rect1, &Brush);
pDC ->FillSolidRect(rect2, RGB(255, 0, 0));
pDC ->SelectObject(pOldBrush);
从上面知道画刷的定义与选入
CBrush Brush(HS_BDIAGONAL,RGB(255, 0, 0));
CBrush *pOldBrush = pDC ->SelectObject(&Brush);
原文:http://www.cnblogs.com/qbin/p/4965826.html