目录
1.实验目的
1)创建一个多文档应用程序MyMdi,可以在这个多文档中可以输入文本、显示静态图、动态图以及显示对话框进行操作。
2)定义8个类,分别是:
CMyMdiDoc类(CMyMdiDoc.h,CMyMdiDoc.cpp),
CMyMdiDoc2类(CMyMdiDoc2.h,CMyMdiDoc2.cpp),
CMyMdiDoc3类(CMyMdiDoc3.h,CMyMdiDoc3.cpp),
CMyMdiView类(CMyMdiView.h,CMyMdiView.cpp),
CMyMdiView2类(CMyMdiView2.h,CMyMdiView2.cpp),
CMyMdiView3类(CMyMdiView3.h,CMyMdiView3.cpp),
CDlgInput2类(CDlgInput2.h,CDlgInput2.cpp),
Shape类(shape.h,shape.cpp)。
4)第一个视图类的基类为CEditView(CView的子类),可以录入字符串。
5)第二个文档在CMyMdiView2类的OnDraw()函数中画出静态图,一共6种图形。用鼠标拖拽即可画出图,设置了2种颜色的画笔和2种颜色的画刷。
6)在第三个文档菜单栏“编辑”中点击“打开对话框”可以打开对话框,更改和查看学生信息。
7)在第三个文档对话框中有6种控件存放学生信息,在MyMdiDoc3类的OnShowDialog()函数中进行设置,单击“改变显示文本”按钮将信息在编辑框中显示来。
2.多个类的继承关系结构图
3.每个类的定义,包括.h文件和.cpp文件
1)MyMdiDoc.h
// MyMdiDoc.h : interface of the CMyMdiDoc class
//
/
#if !defined(AFX_MYMDIDOC_H__01A2DF87_A92B_4D7C_9EE4_02BC092409A7__INCLUDED_)
#define AFX_MYMDIDOC_H__01A2DF87_A92B_4D7C_9EE4_02BC092409A7__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CMyMdiDoc : public CDocument
{
protected: // create from serialization only
CMyMdiDoc();
DECLARE_DYNCREATE(CMyMdiDoc)
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{
{AFX_VIRTUAL(CMyMdiDoc)
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CMyMdiDoc();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{
{AFX_MSG(CMyMdiDoc)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/
//{
{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_MYMDIDOC_H__01A2DF87_A92B_4D7C_9EE4_02BC092409A7__INCLUDED_)
2)MyMdiDoc.cpp
#include "stdafx.h"
#include "MyMdi.h"
#include "MyMdiDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/
// CMyMdiDoc
IMPLEMENT_DYNCREATE(CMyMdiDoc, CDocument)
BEGIN_MESSAGE_MAP(CMyMdiDoc, CDocument)
//{
{AFX_MSG_MAP(CMyMdiDoc)
// 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()
/
// CMyMdiDoc construction/destruction
CMyMdiDoc::CMyMdiDoc()
{
// TODO: add one-time construction code here
}
CMyMdiDoc::~CMyMdiDoc()
{
}
BOOL CMyMdiDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/
// CMyMdiDoc serialization
void CMyMdiDoc::Serialize(CArchive& ar)
{
// CEditView contains an edit control which handles all serialization
((CEditView*)m_viewList.GetHead())->SerializeRaw(ar);
}
/
// CMyMdiDoc diagnostics
#ifdef _DEBUG
void CMyMdiDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CMyMdiDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/
// CMyMdiDoc commands
3)MyMdiDoc2.h
#if !defined(AFX_MYMDIDOC2_H__EDDF1E07_7349_4853_9849_812ACAC4CAFD__INCLUDED_)
#define AFX_MYMDIDOC2_H__EDDF1E07_7349_4853_9849_812ACAC4CAFD__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// MyMdiDoc2.h : header file
//
/
// CMyMdiDoc2 document
class CMyMdiDoc2 : public CDocument
{
protected:
CMyMdiDoc2(); // protected constructor used by dynamic creation
DECLARE_DYNCREATE(CMyMdiDoc2)
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{
{AFX_VIRTUAL(CMyMdiDoc2)
public:
virtual void Serialize(CArchive& ar); // overridden for document i/o
protected:
virtual BOOL OnNewDocument();
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CMyMdiDoc2();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
// Generated message map functions
protected:
//{
{AFX_MSG(CMyMdiDoc2)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{
{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_MYMDIDOC2_H__EDDF1E07_7349_4853_9849_812ACAC4CAFD__INCLUDED_)
4)MyMdiDoc2.cpp
#include "stdafx.h"
#include "MyMdi.h"
#include "MyMdiDoc2.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/
// CMyMdiDoc2
IMPLEMENT_DYNCREATE(CMyMdiDoc2, CDocument)
CMyMdiDoc2::CMyMdiDoc2()
{
}
BOOL CMyMdiDoc2::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
return TRUE;
}
CMyMdiDoc2::~CMyMdiDoc2()
{
}
BEGIN_MESSAGE_MAP(CMyMdiDoc2, CDocument)
//{
{AFX_MSG_MAP(CMyMdiDoc2)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/
// CMyMdiDoc2 diagnostics
#ifdef _DEBUG
void CMyMdiDoc2::AssertValid() const
{
CDocument::AssertValid();
}
void CMyMdiDoc2::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/
// CMyMdiDoc2 serialization
void CMyMdiDoc2::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/
// CMyMdiDoc2 commands
5)MyMdiDoc.3h
#if !defined(AFX_MYMDIDOC3_H__7C8DD25D_2DAF_4C7B_A2C3_60F6C9C09A23__INCLUDED_)
#define AFX_MYMDIDOC3_H__7C8DD25D_2DAF_4C7B_A2C3_60F6C9C09A23__INCLUDED_
#include "DlgInput.h"
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// MyMdiDoc3.h : header file
//
/
// CMyMdiDoc3 document
class CMyMdiDoc3 : public CDocument
{
protected:
CMyMdiDoc3(); // protected constructor used by dynamic creation
DECLARE_DYNCREATE(CMyMdiDoc3)
// Attributes
public:
CString m_name;
CString m_age;
CString m_str;
CString m_sex;
CString m_check;
CString m_id;
CString m_hobby;
CString m_class;
CString m_identity;
CString m_address;
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{
{AFX_VIRTUAL(CMyMdiDoc3)
public:
virtual void Serialize(CArchive& ar); // overridden for document i/o
protected:
virtual BOOL OnNewDocument();
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CMyMdiDoc3();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
// Generated message map functions
protected:
//{
{AFX_MSG(CMyMdiDoc3)
// NOTE - the ClassWizard will add and remove member functions here.
afx_msg void OnShowDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{
{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_MYMDIDOC3_H__7C8DD25D_2DAF_4C7B_A2C3_60F6C9C09A23__INCLUDED_)
// MyMdiDoc3.cpp : implementation file
//
6)MyMdiDoc3.cpp
#include "stdafx.h"
#include "MyMdi.h"
#include "MyMdiDoc3.h"
#include "DlgInput.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/
// CMyMdiDoc3
IMPLEMENT_DYNCREATE(CMyMdiDoc3, CDocument)
CMyMdiDoc3::CMyMdiDoc3()
{
}
BOOL CMyMdiDoc3::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// 初始化成员变量
m_str = _T("可以点击'编辑'下拉菜单下的'更改信息',编辑学生信息");
return TRUE;
}
CMyMdiDoc3::~CMyMdiDoc3()
{
}
BEGIN_MESSAGE_MAP(CMyMdiDoc3, CDocument)
//{
{AFX_MSG_MAP(CMyMdiDoc3)
// NOTE - the ClassWizard will add and remove mapping macros here.
ON_COMMAND(ID_ShowDialog, OnShowDialog)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/
// CMyM