【VC开源代码栏目提醒】:网学会员为需要VC开源代码的朋友们搜集整理了Ex07_3View.cpp相关资料,希望对各位网友有所帮助!
// Ex07_3View.cpp : implementation of the CEx07_3View class
//
#include "stdafx.h"
#include "Ex07_3.h"
#include "Ex07_3Doc.h"
#include "Ex07_3View.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEx07_3View
IMPLEMENT_DYNCREATE(CEx07_3View, CView)
BEGIN_MESSAGE_MAP(CEx07_3View, CView)
//{{AFX_MSG_MAP(CEx07_3View)
ON_COMMAND(ID_SETUP_PENCOLOR, OnSetupPencolor)
ON_COMMAND(ID_ADRAW_SIN, OnAdrawSin)
ON_WM_TIMER()
ON_COMMAND(ID_ADRAW_STOP, OnAdrawStop)
ON_COMMAND(ID_SETUP_BKCOLOR, OnSetupBkcolor)
ON_COMMAND(ID_ADRAW_COS, OnAdrawCos)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CEx07_3View construction/destruction
CEx07_3View::CEx07_3View()
{
// TODO: add construction code here
m_BKColor=RGB(255,255,255);
m_PenColor=RGB(0,0,0);
}
CEx07_3View::~CEx07_3View()
{
}
BOOL CEx07_3View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CEx07_3View drawing
void CEx07_3View::OnDraw(CDC* pDC)
{
CEx07_3Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
ShowBKColor();
}
/////////////////////////////////////////////////////////////////////////////
// CEx07_3View printing
BOOL CEx07_3View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CEx07_3View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CEx07_3View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CEx07_3View diagnostics
#ifdef _DEBUG
void CEx07_3View::AssertValid() const
{
CView::AssertValid();
}
void CEx07_3View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CEx07_3Doc* CEx07_3View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx07_3Doc)));
return (CEx07_3Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CEx07_3View message handlers
////////////////////单击设置菜单下的各下拉菜单/////////////////////////
void CEx07_3View::OnSetupBkcolor()//单击“背景颜色...”菜单
{
// TODO: Add your command handler code here
CColorDialog colordlg;
if(colordlg.DoModal()==IDOK)
{
m_BKColor=colordlg.GetColor();
}
Invalidate();
}
void CEx07_3View::OnSetupPencolor() //单击“画笔颜色...”菜单
{
// TODO: Add your command handler code here
CColorDialog colordlg;
if(colordlg.DoModal()==IDOK)
{
m_PenColor=colordlg.GetColor();
}
}
//////////////////////显示函数////////////////////
void CEx07_3View::ShowBKColor()//显示背景颜色
{
CClientDC dc(this);
CRect rect;
GetClientRect(&rect);
CBrush newBrush,*pOldBrush;
newBrush.CreateSolidBrush(m_BKColor);
pOldBrush=dc.SelectObject(&newBrush);//保存原画笔,选中新画笔
dc.Rectangle(rect);
dc.SelectObject(pOldBrush);//恢复原画笔
}
////////////////////单击动态菜单下的各下拉菜单/////////////////////////
void CEx07_3View::OnAdrawSin() //单击“动态绘正玄曲线”菜单
{
// TODO: Add your command handler code here
CClientDC dc(this);
newPen.CreatePen(PS_SOLID,3,m_PenColor);
pOldPen=dc.SelectObject(&newPen);
dc.MoveTo(100,100);
for(int i=0;i<100;i++)
{
Sleep(100);
dc.LineTo(100+i,100);
}
dc.MoveTo(100,100);
for( i=0;i<100;i++)
{
Sleep(100);
dc.LineTo(100+i*1,(int)(100+50*sin(20*6.28*i)));
}
dc.SelectObject(pOldPen);
}
void CEx07_3View::OnAdrawCos() //单击“开始绘余弦曲线”菜单
{
// TODO: Add your command handler code here
SetTime