原型为:
CPen(int style, int width width, COLORREF color);
COLORREF RGB( //宏
BYTE bRed,
BYTE bGreen,
BYTE bBlue
);
画笔的样式 style
样式 说明
PS_SOLID 画实绩
PS_DASH 画虚线
PS_DOT 画占线
PS_DASHDOT 画点划线
PS_DASHDOTDOT 画双点划线
PS_NULL 笔画不可见的画笔
PS_INSIDEFRAME 在一个图形内画边线的画笔
![](http://blog.beaplat.com/upload/61/2007062942429800.bmp)
注意:在创建了画笔之后,必须使用CDC的成员函数SelectObject把画笔载入DC,以替换DC中原来配置的默画笔,然后才能使用该画笔绘制线条,SelectObject函数的原形为:
CPen * SelectObject(CPen * pPen);
它的返回值为原画笔的指针变量.
void CMy1_2View::OnDraw(CDC* pDC)
{
CMy1_2Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int red=90,green=0,blue=0;
int width=2;
int row=20;
for(int s=0; s<8; s++)
{
int color=RGB(red,green,blue);
CPen newPen(PS_SOLID,width,color);
CPen * oldPen=pDC->SelectObject(&newPen);
pDC->MoveTo(20,row);
pDC->LineTo(300,row);
pDC->SelectObject(oldPen);
red+=32;
green+=16;
blue+=8;
width+=2;
row+=30;
}
}
![](http://blog.beaplat.com/upload/61/2007062964355200.bmp)
void CMy4_3View::OnDraw(CDC* pDC)
{
CMy4_3Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int style[]={PS_SOLID,
PS_DASH,
PS_DOT,
PS_DASHDOT,
PS_DASHDOTDOT,
PS_NULL,
PS_INSIDEFRAME};
int row=20;
for(int s=0; s<7; s++)
{
CPen newPen(style[s],1,#5a5a5a);
CPen *oldPen=pDC->SelectObject(&newPen);
pDC->MoveTo(20,row);
pDC->LineTo(300,row);
pDC->SelectObject(oldPen);
row+=30;
}
}
.
CPen(int style, int width width, COLORREF color);
COLORREF RGB( //宏
BYTE bRed,
BYTE bGreen,
BYTE bBlue
);
画笔的样式 style
样式 说明
PS_SOLID 画实绩
PS_DASH 画虚线
PS_DOT 画占线
PS_DASHDOT 画点划线
PS_DASHDOTDOT 画双点划线
PS_NULL 笔画不可见的画笔
PS_INSIDEFRAME 在一个图形内画边线的画笔
![](http://blog.beaplat.com/upload/61/2007062942429800.bmp)
注意:在创建了画笔之后,必须使用CDC的成员函数SelectObject把画笔载入DC,以替换DC中原来配置的默画笔,然后才能使用该画笔绘制线条,SelectObject函数的原形为:
CPen * SelectObject(CPen * pPen);
它的返回值为原画笔的指针变量.
void CMy1_2View::OnDraw(CDC* pDC)
{
CMy1_2Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int red=90,green=0,blue=0;
int width=2;
int row=20;
for(int s=0; s<8; s++)
{
int color=RGB(red,green,blue);
CPen newPen(PS_SOLID,width,color);
CPen * oldPen=pDC->SelectObject(&newPen);
pDC->MoveTo(20,row);
pDC->LineTo(300,row);
pDC->SelectObject(oldPen);
red+=32;
green+=16;
blue+=8;
width+=2;
row+=30;
}
}
![](http://blog.beaplat.com/upload/61/2007062964355200.bmp)
void CMy4_3View::OnDraw(CDC* pDC)
{
CMy4_3Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int style[]={PS_SOLID,
PS_DASH,
PS_DOT,
PS_DASHDOT,
PS_DASHDOTDOT,
PS_NULL,
PS_INSIDEFRAME};
int row=20;
for(int s=0; s<7; s++)
{
CPen newPen(style[s],1,#5a5a5a);
CPen *oldPen=pDC->SelectObject(&newPen);
pDC->MoveTo(20,row);
pDC->LineTo(300,row);
pDC->SelectObject(oldPen);
row+=30;
}
}
![](http://blog.beaplat.com/upload/61/2007062994235000.bmp)