如何用c++ 生成一个矩形并填充颜色.最简单

2024-12-23 01:37:47
推荐回答(1个)
回答1:

CBrush *pBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
CBrush *pOldBrush = pDC->SelectObject(pBrush);
pDC->SelectObject(pOldBrush);
//创建蓝色画刷,代码如下:
void CDrawView::OnDraw(CDC* pDC)
{
CDrawDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here

CBrush brush;
brush.CreateSolidBrush(RGB(0, 0, 255));
CBrush *pOldBrush = pDC->SelectObject(&brush);

pDC->Rectangle(100, 100, 400, 200);
pDC->SelectObject(pOldBrush);
}