void CMy05301View::OnDraw(CDC* pDC)
{
CMy05301Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetWindowExt(300, 300);
pDC->SetViewportExt(600, 600);
pDC->SetViewportOrg(0, 0);
// 画四个圆形,笔的样式不同
pDC->SelectStockObject(NULL_BRUSH);
CPen pen1, pen2, pen3, pen4;
pen1.CreatePen(PS_DASH, 0, RGB(255, 0, 0));
pDC->SelectObject(&pen1);
pDC->Ellipse(0, 0, 70, 70);
pen2.CreatePen(PS_DASHDOT, 0, RGB(0, 255, 0));
pDC->SelectObject(&pen2);
pDC->Ellipse(25, 0, 95, 70);
pen3.CreatePen(PS_DASHDOTDOT, 0, RGB(0, 0, 255));
pDC->SelectObject(&pen3);
pDC->Ellipse(0, 25, 70, 95);
pen4.CreatePen(PS_DOT, 0, RGB(0, 255, 255));
pDC->SelectObject(&pen4);
pDC->Ellipse(25, 25, 95, 95);
// 画6个圆角矩形,画刷的样式不同
pDC->SelectStockObject(BLACK_PEN);
pDC->RoundRect(120, 0, 165, 45, 10, 10);
pDC->SelectStockObject(DKGRAY_BRUSH);
pDC->RoundRect(165, 0, 210, 45, 10, 10);
pDC->SelectStockObject(GRAY_BRUSH);
pDC->RoundRect(210, 0, 255, 45, 10, 10);
pDC->SelectStockObject(HOLLOW_BRUSH); // 虚画刷
pDC->RoundRect(120, 45, 165, 90, 10, 10);
pDC->SelectStockObject(LTGRAY_BRUSH); // 亮灰色画刷
pDC->RoundRect(165, 45, 210, 90, 10, 10);
pDC->SelectStockObject(WHITE_BRUSH);
pDC->RoundRect(210, 45, 255, 90, 10, 10);
// 画6个矩形,画刷的阴影样式不同
pDC->SelectStockObject(BLACK_PEN);
CBrush brush1, brush2, brush3, brush4, brush5, brush6;
// 45度左上右下阴影线
brush1.CreateHatchBrush(HS_BDIAGONAL, RGB(200, 200, 200));
pDC->SelectObject(&brush1);
pDC->Rectangle(120, 90, 165, 135);
// 45度交叉线
brush2.CreateHatchBrush(HS_DIAGCROSS, RGB(200, 200, 200));
pDC->SelectObject(&brush2);
pDC->Rectangle(165, 90, 210, 135);
// 45度左下右上阴影线
brush3.CreateHatchBrush(HS_FDIAGONAL, RGB(200, 200, 200));
pDC->SelectObject(&brush3);
pDC->Rectangle(210, 90, 255, 135);
// 垂直相交阴影线
brush4.CreateHatchBrush(HS_CROSS, RGB(200, 200, 200));
pDC->SelectObject(&brush4);
pDC->Rectangle(120, 135, 165, 175);
// 水平阴影线
brush5.CreateHatchBrush(HS_HORIZONTAL, RGB(200, 200, 200));
pDC->SelectObject(&brush5);
pDC->Rectangle(165, 135, 210, 175);
// 垂直阴影线
brush6.CreateHatchBrush(HS_VERTICAL, RGB(200, 200, 200));
pDC->SelectObject(&brush6);
pDC->Rectangle(210, 135, 255, 175);
//画饼图
const double Pi = 3.14159265358;
pDC->SelectStockObject(BLACK_PEN);
CBrush RedBrush, BlueBrush, YellowBrush;
RedBrush.CreateSolidBrush(RGB(255, 0, 0));
pDC->SelectObject(&RedBrush);
pDC->Pie(10, 100, 100, 190,
(int)(55 + 45 * cos(2 * Pi / 3)), (int)(145 + 45 * sin(2 * Pi / 3)),
(int)(55 + 45 * cos(0.0)), (int)(145 + 45 * sin(0.0)));
BlueBrush.CreateSolidBrush(RGB(0, 255, 255));
pDC->SelectObject(&BlueBrush);
pDC->Pie(10, 100, 100, 190,
(int)(55 + 45 * cos(4 * Pi / 3)), (int)(145 + 45 * sin(4 * Pi / 3)),
(int)(55 + 45 * cos(2 * Pi / 3)), (int)(145 + 45 * sin(2 * Pi / 3)));
YellowBrush.CreateSolidBrush(RGB(255,255,0));
pDC->SelectObject(&YellowBrush);
pDC->Pie(10, 100, 100, 190,
(int)(55 + 45 * cos(0.0)), (int)(145 + 45 * sin(0.0)),
(int)(55 + 45 * cos(4 * Pi / 3)), (int)(145 + 45 * sin(4 * Pi / 3)));
}
绘图小例子
最新推荐文章于 2018-08-17 15:49:26 发布