面向对象程序设计——多文档综合性试验

1、实验目的

1)创建一个多文档应用程序MyMdi,可以在这个多文档中可以输入文本、显示静态图、动态图以及显示对话框进行操作。
2)第一个视图类的基类为CEditView(CView的子类),可以录入字符串。
3)第二个文档画出静态图,包括五种以上图形。
4)在第二个文档菜单栏“画图”中点击“动态图”可以实现动态画图。,点击“清空”可以将所有内容清空。
5)在第二个文档里画出静态图或动态图可以右击使用橡皮进行擦除。
在第三个文档菜单栏“编辑”中点击某一项可以打开对话框,至少有5种控件存放学生信息,并且每种控件内的信息读取后可以在辑框中显示出来。并且显示信息后可以实现串行化,实现输入、保存并显示信息。

2、各个类的继承关系结构图。

在这里插入图片描述

3、每个类的定义,包括.h文件和.cpp文件。

1)MyMdi.h

// MyMdi.h : main header file for the MYMDI application
//
#if !defined(AFX_MYMDI_H__2FBCC3E9_F38E_41C1_B7A8_0EBBBFA73891__INCLUDED_)
#define AFX_MYMDI_H__2FBCC3E9_F38E_41C1_B7A8_0EBBBFA73891__INCLUDED_

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

#ifndef __AFXWIN_H__
	#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h"       // main symbols

/
// CMyMdiApp:
// See MyMdi.cpp for the implementation of this class
//

class CMyMdiApp : public CWinApp
{
   
public:
	CMyMdiApp();

// Overrides
	// ClassWizard generated virtual function overrides
	//{
   {AFX_VIRTUAL(CMyMdiApp)
	public:
	virtual BOOL InitInstance();
	//}}AFX_VIRTUAL

// Implementation
	//{
   {AFX_MSG(CMyMdiApp)
	afx_msg void OnAppAbout();
		// 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_MYMDI_H__2FBCC3E9_F38E_41C1_B7A8_0EBBBFA73891__INCLUDED_)

2)MyMdi.cpp

// MyMdi.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "MyMdi.h"

#include "MainFrm.h"
#include "ChildFrm.h"
#include "MyMdiDoc.h"
#include "MyMdiView.h"
#include "MyMdiDoc2.h"		//加入头文件
#include "MyMdiView2.h"
#include "MyMdiDoc3.h"		//加入头文件
#include "MyMdiView3.h"


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

/
// CMyMdiApp

BEGIN_MESSAGE_MAP(CMyMdiApp, CWinApp)
	//{
   {AFX_MSG_MAP(CMyMdiApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
		// 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
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
	// Standard print setup command
	ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()

/
// CMyMdiApp construction

CMyMdiApp::CMyMdiApp()
{
   
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/
// The one and only CMyMdiApp object

CMyMdiApp theApp;

/
// CMyMdiApp initialization

BOOL CMyMdiApp::InitInstance()
{
   
	AfxEnableControlContainer();


	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization.
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CMultiDocTemplate* pDocTemplate;
	pDocTemplate = new CMultiDocTemplate(
		IDR_MYMDITYPE,
		RUNTIME_CLASS(CMyMdiDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CMyMdiView));
	AddDocTemplate(pDocTemplate);

	CMultiDocTemplate* pDocTemplate2;
pDocTemplate2 = new CMultiDocTemplate(
IDR_MYMDITYPE2,
RUNTIME_CLASS(CMyMdiDoc2), // MDI派生文档类的CRuntimeClass对象的指针
RUNTIME_CLASS(CChildFrame), // MDI派生子框架类的CRuntimeClass对象的指针
RUNTIME_CLASS(CMyMdiView2)); // 创建文档模板对象
AddDocTemplate(pDocTemplate2); //将新模板添加到应用程序的文档模板列表中

CMultiDocTemplate* pDocTemplate3;
	pDocTemplate3 = new CMultiDocTemplate(
		IDR_MYMDITYPE3,
		RUNTIME_CLASS(CMyMdiDoc3),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CMyMdiView3));
	AddDocTemplate(pDocTemplate3);


	// create main MDI Frame window
	CMainFrame* pMainFrame = new CMainFrame;
	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
		return FALSE;
	m_pMainWnd = pMainFrame;

	// Enable drag/drop open
	m_pMainWnd->DragAcceptFiles();

	// Enable DDE Execute open
	EnableShellOpen();
	RegisterShellFileTypes(TRUE);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	// The main window has been initialized, so show and update it.
	pMainFrame->ShowWindow(m_nCmdShow);
	pMainFrame->UpdateWindow();

	return TRUE;
}


/
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
   
public:
	CAboutDlg();

// Dialog Data
	//{
   {AFX_DATA(CAboutDlg)
	enum {
    IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{
   {AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{
   {AFX_MSG(CAboutDlg)
		// No message handlers
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
   
	//{
   {AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
   
	CDialog::DoDataExchange(pDX);
	//{
   {AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{
   {AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void CMyMdiApp::OnAppAbout()
{
   
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/
// CMyMdiApp message handlers

3)MyMdiDoc.h

// MyMdiDoc.h : interface of the CMyMdiDoc class
//
/

#if !defined(AFX_MYMDIDOC_H__4CCFC2E0_9D27_4259_8C68_45099862CD8E__INCLUDED_)
#define AFX_MYMDIDOC_H__4CCFC2E0_9D27_4259_8C68_45099862CD8E__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__4CCFC2E0_9D27_4259_8C68_45099862CD8E__INCLUDED_)

4)MyMdiDoc.cpp

// MyMdiDoc.cpp : implementation of the CMyMdiDoc class
//

#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 
  • 0
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值