您的位置:首页 > 其它

实训项目

2013-07-18 18:28 99 查看
东软实训之左键+,右键-功能,并且退出提示保存

// 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);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: