计数器

来源:互联网 发布:软件版本升级方案 编辑:程序博客网 时间:2024/04/27 14:55
// countView.cpp : implementation of the CCountView class//#include "stdafx.h"#include "count.h"#include "countDoc.h"#include "countView.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CCountViewIMPLEMENT_DYNCREATE(CCountView, CView)BEGIN_MESSAGE_MAP(CCountView, CView)//{{AFX_MSG_MAP(CCountView)ON_WM_LBUTTONDOWN()ON_WM_RBUTTONDOWN()//}}AFX_MSG_MAP// Standard printing commandsON_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()/////////////////////////////////////////////////////////////////////////////// CCountView construction/destructionCCountView::CCountView(){// TODO: add construction code herenum=0;}CCountView::~CCountView(){}BOOL CCountView::PreCreateWindow(CREATESTRUCT& cs){// TODO: Modify the Window class or styles here by modifying//  the CREATESTRUCT csreturn CView::PreCreateWindow(cs);}/////////////////////////////////////////////////////////////////////////////// CCountView drawingvoid CCountView::OnDraw(CDC* pDC){CCountDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);    CRect rect;this->GetWindowRect(&rect);int x,y;x=rect.Width()/2;y=rect.Height()/2;str.Format("%d",num);pDC->TextOut(x,y,str);// TODO: add draw code for native data hereCFile mfile(_T("data.txt"),CFile::modeWrite|CFile::modeCreate);mfile.Write(str,2);mfile.Flush();mfile.Close();}/////////////////////////////////////////////////////////////////////////////// CCountView printingBOOL CCountView::OnPreparePrinting(CPrintInfo* pInfo){// default preparationreturn DoPreparePrinting(pInfo);}void CCountView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/){// TODO: add extra initialization before printing}void CCountView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/){// TODO: add cleanup after printing}/////////////////////////////////////////////////////////////////////////////// CCountView diagnostics#ifdef _DEBUGvoid CCountView::AssertValid() const{CView::AssertValid();}void CCountView::Dump(CDumpContext& dc) const{CView::Dump(dc);}CCountDoc* CCountView::GetDocument() // non-debug version is inline{ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCountDoc)));return (CCountDoc*)m_pDocument;}#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////// CCountView message handlersvoid CCountView::OnLButtonDown(UINT nFlags, CPoint point) {// TODO: Add your message handler code here and/or call defaultnum+=1;this->Invalidate();CView::OnLButtonDown(nFlags, point);}void CCountView::OnRButtonDown(UINT nFlags, CPoint point) {// TODO: Add your message handler code here and/or call defaultnum-=1;this->Invalidate();CView::OnRButtonDown(nFlags, point);}

原创粉丝点击