📄 exam5_4view.cpp
字号:
// Exam5_4View.cpp : implementation of the CExam5_4View class
//
#include "stdafx.h"
#include "Exam5_4.h"
#include "Exam5_4Doc.h"
#include "Exam5_4View.h"
#include "math.h"
#define Pi 3.1415926
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CExam5_4View
IMPLEMENT_DYNCREATE(CExam5_4View, CView)
BEGIN_MESSAGE_MAP(CExam5_4View, CView)
//{{AFX_MSG_MAP(CExam5_4View)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExam5_4View construction/destruction
CExam5_4View::CExam5_4View()
{
// TODO: add construction code here
}
CExam5_4View::~CExam5_4View()
{
}
BOOL CExam5_4View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CExam5_4View drawing
void CExam5_4View::OnDraw(CDC* pDC)
{
CExam5_4Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetWindowExt(300,300);
pDC->SetViewportExt(600,600);
pDC->SetViewportOrg (0,0);
//画四个圆形(笔的样式不同)
pDC->SelectStockObject(NULL_BRUSH);
CPen NewPen1,NewPen2,NewPen3,NewPen4;
NewPen1.CreatePen(PS_DASH,0,RGB(255,0,0));//创建虚线样式红色画笔
pDC->SelectObject(&NewPen1);
pDC->Ellipse(0,0,70,70);
NewPen2.CreatePen(PS_DASHDOT,0,RGB(0,255,0));//创建点划线样式绿色画笔
pDC->SelectObject(&NewPen2);
pDC->Ellipse(25,0,95,70);
NewPen3.CreatePen(PS_DASHDOTDOT,0,RGB(0,0,255));//创建双点划线样式蓝色画笔
pDC->SelectObject(&NewPen3);
pDC->Ellipse(0,25,70,95);
NewPen4.CreatePen(PS_DOT,0,RGB(0,255,255));//创建点线样式天蓝色画笔
pDC->SelectObject(&NewPen4);
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 NewBrush1,NewBrush2,NewBrush3,NewBrush4,NewBrush5,NewBrush6;
//创建45度左上右下阴影线
NewBrush1.CreateHatchBrush(HS_BDIAGONAL,RGB(200,200,200));
pDC->SelectObject(&NewBrush1);
pDC->Rectangle(120,90,165,135);
//创建45度交叉线
NewBrush2.CreateHatchBrush(HS_DIAGCROSS,RGB(200,200,200));
pDC->SelectObject(&NewBrush2);
pDC->Rectangle(165,90,210,135);
//创建45度左下右上阴影线线
NewBrush3.CreateHatchBrush(HS_FDIAGONAL,RGB(200,200,200));
pDC->SelectObject(&NewBrush3);
pDC->Rectangle(210,90,255,135);
//创建垂直相交阴影线
NewBrush4.CreateHatchBrush(HS_CROSS,RGB(200,200,200));
pDC->SelectObject(&NewBrush4);
pDC->Rectangle(120,135,165,175);
//创建水平阴影线
NewBrush5.CreateHatchBrush(HS_HORIZONTAL,RGB(200,200,200));
pDC->SelectObject(&NewBrush5);
pDC->Rectangle(165,135,210,175);
//创建垂直阴影线
NewBrush6.CreateHatchBrush(HS_VERTICAL,RGB(200,200,200));
pDC->SelectObject(&NewBrush6);
pDC->Rectangle(210,135,255,175);
//画饼图
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)),(int)(145+45*sin(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)),(int)(145+45*sin(0)),
(int)(55+45*cos(4*Pi/3)),(int)(145+45*sin(4*Pi/3)));
}
/////////////////////////////////////////////////////////////////////////////
// CExam5_4View printing
BOOL CExam5_4View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CExam5_4View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CExam5_4View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CExam5_4View diagnostics
#ifdef _DEBUG
void CExam5_4View::AssertValid() const
{
CView::AssertValid();
}
void CExam5_4View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CExam5_4Doc* CExam5_4View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CExam5_4Doc)));
return (CExam5_4Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CExam5_4View message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -