东软实训01-计数器ver1

// homeword1View.cpp : implementation of the CHomeword1View class
// 单击左键加1 ,单击右键 减1

#include "stdafx.h"
#include "homeword1.h"

#include "homeword1Doc.h"
#include "homeword1View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CHomeword1View

IMPLEMENT_DYNCREATE(CHomeword1View, CView)

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

/////////////////////////////////////////////////////////////////////////////
// CHomeword1View construction/destruction

CHomeword1View::CHomeword1View():num(0)
{
	// TODO: add construction code here

}

CHomeword1View::~CHomeword1View()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CHomeword1View drawing

void CHomeword1View::OnDraw(CDC* pDC)
{
	CHomeword1Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	CRect rect;
	int x, y;
	GetWindowRect(&rect);
	x = rect.Width();//得到客户区x
	y = rect.Height();
	CString str;
	str.Format("%d",num);
	pDC->TextOut(x/2,y/2,str);
}

/////////////////////////////////////////////////////////////////////////////
// CHomeword1View printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CHomeword1View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CHomeword1View message handlers

void CHomeword1View::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	num += 1;
	this->Invalidate();
	CView::OnLButtonDown(nFlags, point);
}

void CHomeword1View::OnRButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	num -= 1;
	this->Invalidate();
	CView::OnRButtonDown(nFlags, point);
}

你可能感兴趣的:(东软实训01-计数器ver1)