【VC开源代码栏目提醒】:网学会员在VC开源代码频道为大家收集整理了CPaint_6View.cpp提供大家参考,希望对大家有所帮助!
// CPaint_6View.cpp : implementation of the CCPaint_6View class
//
#include "stdafx.h"
#include "CPaint_6.h"
#include "CPaint_6Doc.h"
#include "CPaint_6View.h"
#include"math.h"
#define PI 3.1415926
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCPaint_6View
IMPLEMENT_DYNCREATE(CCPaint_6View, CView)
BEGIN_MESSAGE_MAP(CCPaint_6View, CView)
//{{AFX_MSG_MAP(CCPaint_6View)
ON_WM_PAINT()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CCPaint_6View construction/destruction
CCPaint_6View::CCPaint_6View()
{
// TODO: add construction code here
}
CCPaint_6View::~CCPaint_6View()
{
}
BOOL CCPaint_6View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCPaint_6View drawing
void CCPaint_6View::OnDraw(CDC* pDC)
{
CCPaint_6Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CCPaint_6View printing
BOOL CCPaint_6View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCPaint_6View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCPaint_6View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCPaint_6View diagnostics
#ifdef _DEBUG
void CCPaint_6View::AssertValid() const
{
CView::AssertValid();
}
void CCPaint_6View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCPaint_6Doc* CCPaint_6View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCPaint_6Doc)));
return (CCPaint_6Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCPaint_6View message handlers
void CCPaint_6View::OnPaint()
{
CPaintDC dc(this); // device context for painting
CPen pen(PS_SOLID,4,RGB(255,0,0));
CPen *pOldPen;
pOldPen=dc.SelectObject(&pen); //添加一个画笔
int nRevenuse[4]={125,376,252,184};
CRect rect;
GetClientRect(&rect);
dc.SetViewportOrg(rect.Width()/2,rect.Height()/2);
//将原点移至窗口中心
int nTotal=0;
for(int i=0;i<4;i++)
nTotal+=nRevenuse[i];
int x1=0;
int y1=-1000;
int nSum=0;
for(i=0;i<4;i++)
{
nSum+=nRevenuse[i];
double rad=((double)(nSum*2*PI)/(double)nTotal)+PI;
int x2=(int)(sin(rad)*1000);
int y2=(int)(cos(rad)*1000*3)/4;
dc.Pie(-200,-150,200,150,x1,y1,x2,y2); //画一个饼图
x1=x2;
y1=y2;
}
dc.SelectObject(pOldPen);
// Do not call CView::OnPaint() for painting messages
}