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

📄 mdi.cpp

📁 msdn提供的文档视结构的例子
💻 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

/////////////////////////////////////////////////////////////////////////////
// CMDIApp

BEGIN_MESSAGE_MAP(CMDIApp, CWinApp)
	//{{AFX_MSG_MAP(CMDIApp)
	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()

/////////////////////////////////////////////////////////////////////////////
// CMDIApp construction

CMDIApp::CMDIApp()
{
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CMDIApp object

CMDIApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CMDIApp initialization

BOOL CMDIApp::InitInstance()
{
	// Register the application's document templates.  Document templates
	// serve as the connection between documents, frame windows and views.

	CMultiDocTemplate* pDocTemplate;
	pDocTemplate = new CMultiDocTemplate(
		IDR_HELLOTYPE,
		RUNTIME_CLASS(CHelloDoc),
		RUNTIME_CLASS(CHelloFrame), // custom MDI child frame
		RUNTIME_CLASS(CHelloView));
	AddDocTemplate(pDocTemplate);

// Add Bounce template to list

	CMultiDocTemplate* pBounceTemplate;
	pBounceTemplate = new CMultiDocTemplate(
		IDR_BOUNCETYPE,
		RUNTIME_CLASS(CBounceDoc),
		RUNTIME_CLASS(CBounceFrame), // custom MDI child frame
		RUNTIME_CLASS(CBounceView));
	AddDocTemplate(pBounceTemplate);

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

	// 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 CMDIApp::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)
};
/////////////////////////////////////////////////////////////////////////////
// CMDIApp 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 CMDIApp::OnNewHello()
{

// Searches template list for a document type
// containing the "Hello" string

	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 CMDIApp::OnNewBounce()
{
// Searches template list for a document type
// containing the "Bounce" string

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

//DEL void CMDIApp::OnTemplate() 
//DEL {
//DEL 	// TODO: Add your command handler code here
//DEL //	CMDIFrameWnd *pFrame = 
//DEL   //           (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
//DEL 
//DEL // Get the active MDI child window.
//DEL //	CMDIChildWnd *pChild = 
//DEL  //            (CMDIChildWnd *) pFrame->GetActiveFrame();
//DEL //	(CView*)pnactView=pChild->GetActiveView();
//DEL /*CView* pView = NULL;
//DEL 	if (GetActiveView() == NULL)
//DEL 	{
//DEL 		CWnd* pWnd = GetDescendantWindow(AFX_IDW_PANE_FIRST, TRUE);
//DEL 		if (pWnd != NULL && pWnd->IsKindOf(RUNTIME_CLASS(CView)))
//DEL 		{
//DEL 			pView = (CView*)pWnd;
//DEL 			SetActiveView(pView, FALSE);
//DEL 		}
//DEL 	}
//DEL 
//DEL 	if (bMakeVisible)
//DEL 	{
//DEL 		// send initial update to all views (and other controls) in the frame
//DEL 		SendMessageToDescendants(WM_INITIALUPDATE, 0, 0, TRUE, TRUE);
//DEL 
//DEL 		// give view a chance to save the focus (CFormView needs this)
//DEL 		if (pView != NULL)
//DEL 			pView->OnActivateFrame(WA_INACTIVE, this);
//DEL 
//DEL 		// finally, activate the frame
//DEL 		// (send the default show command unless the main desktop window)
//DEL 		int nCmdShow = -1;      // default
//DEL 		CWinApp* pApp = AfxGetApp();
//DEL 		if (pApp != NULL && pApp->m_pMainWnd == this)
//DEL 		{
//DEL 			nCmdShow = pApp->m_nCmdShow; // use the parameter from WinMain
//DEL 			pApp->m_nCmdShow = -1; // set to default after first time
//DEL 		}
//DEL 		ActivateFrame(nCmdShow);
//DEL 		if (pView != NULL)
//DEL 			pView->OnActivateView(TRUE, pView, pView);
//DEL 	}
//DEL 
//DEL 	// update frame counts and frame title (may already have been visible)
//DEL 	if (pDoc != NULL)
//DEL 		pDoc->UpdateFrameCounts();
//DEL 	OnUpdateFrameTitle(TRUE);*/
//DEL CView* pView = NULL;
//DEL 	CWnd* pWnd = m_pMainWnd->GetDescendantWindow(AFX_IDW_PANE_FIRST, TRUE);
//DEL 			if (pWnd != NULL && pWnd->IsKindOf(RUNTIME_CLASS(CView)))
//DEL 		{
//DEL 			pView = (CView*)pWnd;
//DEL //			pView->OnActivateView(TRUE, pView, pView);
//DEL 		//	SetActiveView(pView, FALSE);
//DEL 		}
//DEL 
//DEL 	/*POSITION pos;
//DEL 	POSITION pos1;
//DEL 	pos=GetFirstDocTemplatePosition();
//DEL 	
//DEL 	CDocTemplate * temp;
//DEL 	CDocument * cod;
//DEL 	if (pos!=NULL)
//DEL 	{
//DEL 		temp=GetNextDocTemplate(pos);
//DEL 		pos1=temp->GetFirstDocPosition();
//DEL 		if (pos1!=NULL)
//DEL 		{
//DEL 			cod=temp->GetNextDoc(pos1);
//DEL 			cod->SetTitle("di1  ");
//DEL 			//(CView*) pWnd
//DEL 			//CWinApp* pApp= AfxGetApp();
//DEL 			
//DEL 			cod->UpdateFrameCounts();
//DEL 			//(CView*)pWnd->OnActivateView(
//DEL //			pFrame->SetActiveView((CView*)pWnd
//DEL 		//this->m_pMainWnd->GetActiveWindow();
//DEL 		}
//DEL 	}*/	
//DEL }

⌨️ 快捷键说明

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