实训项目

东软实训之左键+,右键-功能,并且退出提示保存

// jiView.h : interface of the CJiView class
//
/

#if !defined(AFX_JIVIEW_H__EBC5C1EC_CA4F_47A4_82FE_1022029E2AD2__INCLUDED_)
#define AFX_JIVIEW_H__EBC5C1EC_CA4F_47A4_82FE_1022029E2AD2__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


class CJiView : public CView
{
protected: // create from serialization only
 CJiView();
 DECLARE_DYNCREATE(CJiView)

// Attributes
public:
 CJiDoc* GetDocument();

// Operations
public:

private:
 int num;//添加成员变量
// Overrides
 // ClassWizard generated virtual function overrides
 //{{AFX_VIRTUAL(CJiView)
 public:
 virtual void OnDraw(CDC* pDC);  // overridden to draw this view
 virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
 protected:
 virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
 virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
 virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
 //}}AFX_VIRTUAL

// Implementation
public:
 virtual ~CJiView();
#ifdef _DEBUG
 virtual void AssertValid() const;
 virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
 //{{AFX_MSG(CJiView)
 afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
 afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
 //}}AFX_MSG
 DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG  // debug version in jiView.cpp
inline CJiDoc* CJiView::GetDocument()
   { return (CJiDoc*)m_pDocument; }
#endif

/

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_JIVIEW_H__EBC5C1EC_CA4F_47A4_82FE_1022029E2AD2__INCLUDED_)

 

 


 

// jiDoc.cpp : implementation of the CJiDoc class
//

#include "stdafx.h"
#include "ji.h"

#include "jiDoc.h"

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

/
// CJiDoc

IMPLEMENT_DYNCREATE(CJiDoc, CDocument)

BEGIN_MESSAGE_MAP(CJiDoc, CDocument)
 //{{AFX_MSG_MAP(CJiDoc)
  // NOTE - the ClassWizard will add and remove mapping macros here.
  //    DO NOT EDIT what you see in these blocks of generated code!
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/
// CJiDoc construction/destruction

CJiDoc::CJiDoc():num(0)//成员变量初始化
{
 // TODO: add one-time construction code here

}

CJiDoc::~CJiDoc()
{
}

BOOL CJiDoc::OnNewDocument()
{
 if (!CDocument::OnNewDocument())
  return FALSE;//刷新
 num=0;//新建后初始值
 // TODO: add reinitialization code here
 // (SDI documents will reuse this document)

 return TRUE;
}

 

/
// CJiDoc serialization

void CJiDoc::Serialize(CArchive& ar)
{
 if (ar.IsStoring())
 {
  ar<<num;//写入
  // TODO: add storing code here
 }
 else
 {
  ar>>num;//读入
  // TODO: add loading code here
 }
}

/
// CJiDoc diagnostics

#ifdef _DEBUG
void CJiDoc::AssertValid() const
{
 CDocument::AssertValid();
}

void CJiDoc::Dump(CDumpContext& dc) const
{
 CDocument::Dump(dc);
}
#endif //_DEBUG

/
// CJiDoc commands

 

 

// jiView.cpp : implementation of the CJiView class
//

#include "stdafx.h"
#include "ji.h"

#include "jiDoc.h"
#include "jiView.h"

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

/
// CJiView

IMPLEMENT_DYNCREATE(CJiView, CView)

BEGIN_MESSAGE_MAP(CJiView, CView)
 //{{AFX_MSG_MAP(CJiView)
 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()

/
// CJiView construction/destruction

CJiView::CJiView():num(0)//成员变量初始化
{
 // TODO: add construction code here

}

CJiView::~CJiView()
{
}

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

 return CView::PreCreateWindow(cs);
}

/
// CJiView drawing

void CJiView::OnDraw(CDC* pDC)
{
 CJiDoc* pDoc = GetDocument();
 ASSERT_VALID(pDoc);
 CString str;
 str.Format("计数%d",num);//格式转换
 pDC->TextOut(100,100,str);//在视图上显示


 // TODO: add draw code for native data here
}

/
// CJiView printing

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

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

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

/
// CJiView diagnostics

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

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

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

/
// CJiView message handlers

void CJiView::OnLButtonDown(UINT nFlags, CPoint point)
{
 // TODO: Add your message handler code here and/or call default
 CJiDoc* pDoc = GetDocument();//从ondraw中复制过来
 ASSERT_VALID(pDoc);//从ondraw中复制过来
 ++num;//实现鼠标左键+
 pDoc->SetModifiedFlag();//修改后保存提示
 this->Invalidate();//刷新
 CView::OnLButtonDown(nFlags, point);
}

void CJiView::OnRButtonDown(UINT nFlags, CPoint point)
{
 // TODO: Add your message handler code here and/or call default
 CJiDoc* pDoc = GetDocument();//从ondraw中复制过来
 ASSERT_VALID(pDoc);//从ondraw中复制过来
 --num;//实现鼠标右键-
 pDoc->SetModifiedFlag();//修改后保存提示
 this->Invalidate();//刷新
 CView::OnRButtonDown(nFlags, point);
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值