【VC开源代码栏目提醒】:网学会员鉴于大家对VC开源代码十分关注,论文会员在此为大家搜集整理了“CPaint_2View.cpp”一文,供大家参考学习
// CPaint_2View.cpp : implementation of the CCPaint_2View class
//
#include "stdafx.h"
#include "CPaint_2.h"
#include "CPaint_2Doc.h"
#include "CPaint_2View.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define SEGMENTS 500
#define PI 3.1415926
/////////////////////////////////////////////////////////////////////////////
// CCPaint_2View
IMPLEMENT_DYNCREATE(CCPaint_2View, CView)
BEGIN_MESSAGE_MAP(CCPaint_2View, CView)
//{{AFX_MSG_MAP(CCPaint_2View)
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_2View construction/destruction
CCPaint_2View::CCPaint_2View()
{
// TODO: add construction code here
}
CCPaint_2View::~CCPaint_2View()
{
}
BOOL CCPaint_2View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCPaint_2View drawing
void CCPaint_2View::OnDraw(CDC* pDC)
{
CCPaint_2Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CCPaint_2View printing
BOOL CCPaint_2View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCPaint_2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCPaint_2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCPaint_2View diagnostics
#ifdef _DEBUG
void CCPaint_2View::AssertValid() const
{
CView::AssertValid();
}
void CCPaint_2View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCPaint_2Doc* CCPaint_2View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCPaint_2Doc)));
return (CCPaint_2Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCPaint_2View message handlers
void CCPaint_2View::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect rect;
CPen pen(PS_SOLID,10,RGB(255,0,0));
CPen *pOldPen=dc.SelectObject(&pen); //加入一个新的红色画笔
GetClientRect(&rect); //获得客户区的大小
int nWidth=rect.Width();
int nHeigh=rect.Height();
CPoint aPoint[SEGMENTS];
for(int i=0;i<SEGMENTS;i++)
{
aPoint[i].x=(i*nWidth)/SEGMENTS;
aPoint[i].y=(int)((nHeigh/2)*(1-(sin((2*PI*i)/SEGMENTS))));
} //绘制各个正弦曲线点
dc.Polyline(aPoint,SEGMENTS); //将各个孤立点连接起来
dc.SelectObject(pOldPen); //还原旧的画笔
// Do not call CView::OnPaint() for painting messages
}