建立一个MFC单文档应用程序。
在view类里面的OnDraw 函数下添加如下代码,即可
CBrush redBrush,blueBrush;
CPen redPen,bluePen;
redPen.CreatePen(PS_SOLID | PS_COSMETIC,1,RGB(255,0,0));
bluePen.CreatePen(PS_SOLID | PS_COSMETIC,1,RGB(0,0,255));
redBrush.CreateSolidBrush(RGB(255,0,0)); //红色笔刷
blueBrush.CreateSolidBrush(RGB(0,0,255)); //蓝色笔刷
CBrush *oldBrush = pDC->SelectObject(&redBrush);
CPen *oldPen = pDC->SelectObject(&redPen);
CRect rect(100,100,400,400); //用于画图的矩形
pDC->Pie(&rect,CPoint(100,250),CPoint(400,250)); //画一个半圆
pDC->SelectObject(&bluePen);
pDC->SelectObject(&blueBrush);
pDC->Pie(&rect,CPoint(400,250),CPoint(100,250)); //将另外半圆填充成蓝色
pDC->SelectObject(&redBrush);
pDC->SelectObject(&redPen);