?? mdi.cpp
字號(hào):
// 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()
{
//注冊(cè)應(yīng)用程序的文檔模板,文檔模板連接文檔、框架窗口和視
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);
// 創(chuàng)建主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);
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -