⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mdi.cpp

📁 图书馆CD上下载的编辑画刷工具的例子源代码
💻 CPP
字号:
// MDI.cpp : Defines the class behaviors for the application.
//

// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) 1992-1998 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.

#include "stdafx.h"
#include "MDI.h"

#include "MainFrm.h"
#include "HelloFrm.h"
#include "HelloDoc.h"
#include "HelloVw.h"

//Added for Bounce document
#include "BncFrm.h"
#include "BncDoc.h"
#include "BncVw.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMDISampleApp

BEGIN_MESSAGE_MAP(CMDISampleApp, CWinApp)
	//{{AFX_MSG_MAP(CMDISampleApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	ON_COMMAND(ID_FILE_NEWHELLO, OnNewHello)
	ON_COMMAND(ID_FILE_NEWBOUNCE, OnNewBounce)
	//}}AFX_MSG_MAP
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMDISampleApp construction

CMDISampleApp::CMDISampleApp()
{
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CMDISampleApp object

CMDISampleApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CMDISampleApp initialization

BOOL CMDISampleApp::InitInstance()
{
	//注册应用程序的文档模板,文档模板连接文档、框架窗口和视

	CMultiDocTemplate* pDocTemplate;
	pDocTemplate = new CMultiDocTemplate(
		IDR_HELLOTYPE,
		RUNTIME_CLASS(CHelloDoc),
		RUNTIME_CLASS(CHelloFrame), // 定制MDI子框架
		RUNTIME_CLASS(CHelloView));
	AddDocTemplate(pDocTemplate);

	// 在文档模板列表中增加弹球(Bounce)模板

	CMultiDocTemplate* pBounceTemplate;
	pBounceTemplate = new CMultiDocTemplate(
		IDR_BOUNCETYPE,
		RUNTIME_CLASS(CBounceDoc),
		RUNTIME_CLASS(CBounceFrame), // 定制MDI子框架
		RUNTIME_CLASS(CBounceView));
	AddDocTemplate(pBounceTemplate);

	// 创建主MDI框架窗口 
	CMainFrame* pMainFrame = new CMainFrame;
	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
		return FALSE;
	m_pMainWnd = pMainFrame;

	// 显示并刷新主窗口
	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 CMDISampleApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// other globals

// Color array maps colors to top-level Color menu

COLORREF NEAR colorArray[] =
{
	RGB (0, 0, 0),
	RGB (255, 0, 0),
	RGB (0, 255, 0),
	RGB (0, 0, 255),
	RGB (255, 255, 255)
};
/////////////////////////////////////////////////////////////////////////////
// CMDISampleApp commands

// The following two command handlers provides an
// alternative way to open documents by hiding the fact
// that the application has multiple templates. The
// default method uses a dialog with a listing of
// possible types to choose from.

void CMDISampleApp::OnNewHello()
{
	//在模板列表中查找包含字符串"Hello"的文档类型
	POSITION curTemplatePos = GetFirstDocTemplatePosition();

	while(curTemplatePos != NULL)
	{
		CDocTemplate* curTemplate =
			GetNextDocTemplate(curTemplatePos);
		CString str;
		curTemplate->GetDocString(str, CDocTemplate::docName);
		if(str == _T("Hello"))
		{
			curTemplate->OpenDocumentFile(NULL);
			return;
		}
	}
	AfxMessageBox(IDS_NOHELLOTEMPLATE);
}

void CMDISampleApp::OnNewBounce()
{
	//在模板列表中查找包含字符串"Bounce"的文档类型
	POSITION curTemplatePos = GetFirstDocTemplatePosition();

	while(curTemplatePos != NULL)
	{
		CDocTemplate* curTemplate =
			GetNextDocTemplate(curTemplatePos);
		CString str;
		curTemplate->GetDocString(str, CDocTemplate::docName);
		if(str == _T("Bounce"))
		{
			curTemplate->OpenDocumentFile(NULL);
			return;
		}
	}
	AfxMessageBox(IDS_NOBOUNCETEMPLATE);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -