//在单文档或对话框中的ondraw,onpaint函数中加入以下代码
CDC* pDC=GetDC();//定义pDC 单文档中可以不定义
CPen pen[5];
pen[0].CreatePen(PS_SOLID,3,RGB(255,0,0));//创建实线画笔
pen[1].CreatePen(PS_DASH,1,RGB(0,255,0));//创建虚线画笔
pen[2].CreatePen(PS_DOT,1,RGB(0,0,255));//点线
pen[3].CreatePen(PS_DASHDOT,1,RGB(0,255,255));//点划线
pen[4].CreatePen(PS_DASHDOTDOT,1,RGB(255,0,255));//双点划线
CPen *pOldPen;
pOldPen=pDC->SelectObject(&pen[0]);
pDC->Rectangle(10,10,110,110);
pDC->TextOut(10,115,"绘制矩形");
pDC->SelectObject(&pen[1]);
CPoint pts[]={CPoint(190,20),CPoint(200,60),CPoint(270,40),CPoint(210,80),CPoint(250,100),CPoint(300,3),CPoint(310,80)};
pDC->Polyline(pts,7);
pDC->TextOut(180,115,"绘制多段折线");
pDC->SelectObject((&pen[2]));
pDC->Ellipse(10,140,160,240);
pDC->SelectObject(&pen[3]);
pDC->Pie(20,150,150,230,160,160,10,160);
pDC->SelectObject(&pen[4]);
pDC->Arc(20,150,150,230,10,220,160,220);
pDC->TextOut(10,245,"绘制椭圆,弧线和饼图");
pDC->SetTextColor(RGB(0,0,255));
pDC->TextOut(220,200,"使用不同的画笔绘制各种图形");
pDC->SelectObject(pOldPen);
for(int i=0;i<5;i++)
{
pen[i].DeleteObject();
}