⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1_4view.cpp

📁 一本游戏的入门书籍并附有源代码
💻 CPP
字号:
// 1_4View.cpp : implementation of the CMy1_4View class
//

#include "stdafx.h"
#include "1_4.h"

#include "1_4Doc.h"
#include "1_4View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMy1_4View

IMPLEMENT_DYNCREATE(CMy1_4View, CView)

BEGIN_MESSAGE_MAP(CMy1_4View, CView)
	//{{AFX_MSG_MAP(CMy1_4View)
	ON_WM_KEYDOWN()
	ON_WM_LBUTTONDOWN()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMy1_4View construction/destruction

CMy1_4View::CMy1_4View()
{
	// TODO: add construction code here
    center.x=400;
	center.y=200;
	ir=50;
}

CMy1_4View::~CMy1_4View()
{
}

BOOL CMy1_4View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMy1_4View drawing

void CMy1_4View::OnDraw(CDC* pDC)
{
	CMy1_4Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
    pDC->Ellipse(center.x-ir,center.y-ir,center.x+ir,center.y+ir);
}

/////////////////////////////////////////////////////////////////////////////
// CMy1_4View printing

BOOL CMy1_4View::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CMy1_4View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CMy1_4View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CMy1_4View diagnostics

#ifdef _DEBUG
void CMy1_4View::AssertValid() const
{
	CView::AssertValid();
}

void CMy1_4View::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CMy1_4Doc* CMy1_4View::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMy1_4Doc)));
	return (CMy1_4Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMy1_4View message handlers

void CMy1_4View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	//利用方向键左右上下移动20
	switch(nChar)
	{
	case VK_LEFT:
	    center.x-=20;
		break;
	case VK_RIGHT:
	    center.x+=20;
		break;		
	case VK_UP:
        center.y-=20;
		break;
	case VK_DOWN:
	    center.y+=20;
		break;
	}
	//重画
	Invalidate();
	CView::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CMy1_4View::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	//把圆移动鼠标指定位置
	//圆心赋值为point
	center=point;
    //重画
	Invalidate();
	CView::OnLButtonDown(nFlags, point);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -