// MFCSdi.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "resource.h"
class CMdiDocument:public CDocument{
//把这几个都写成可以动态创建的
DECLARE_DYNCREATE(CMdiDocument)
public:
};
IMPLEMENT_DYNCREATE(CMdiDocument,CDocument)
class CMdiView:public CEditView{
DECLARE_DYNCREATE(CMdiView)
public:
};
IMPLEMENT_DYNCREATE(CMdiView,CEditView)
class CChildFrame:public CMDIChildWnd{
DECLARE_DYNCREATE(CChildFrame)
public:
};
IMPLEMENT_DYNCREATE(CChildFrame,CMDIChildWnd)
class MFCMdiFrame:public CMDIFrameWnd{
public:
};
class MFCMdiApp:public CWinApp{
DECLARE_MESSAGE_MAP()
public:
virtual BOOL InitInstance();
public:
afx_msg void OnNew();
};
BEGIN_MESSAGE_MAP(MFCMdiApp,CWinApp)
ON_COMMAND(ID_NEW,OnNew)
END_MESSAGE_MAP()
void MFCMdiApp::OnNew(){
OnFileNew();
}
MFCMdiApp theApp;
BOOL MFCMdiApp::InitInstance(){
CMultiDocTemplate *pDocTemp=NULL;
//当前激活的菜单是IDR_CHILDFRM 当关闭了pDocTemp窗口
//激活的是IDR_MAINFRM菜单
pDocTemp=new CMultiDocTemplate(IDR_CHILDFRM,
RUNTIME_CLASS(CMdiDocument),
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CMdiView));
AddDocTemplate(pDocTemp);
MFCMdiFrame *pFrame=new MFCMdiFrame();
pFrame->LoadFrame(IDR_MAINFRM);
m_pMainWnd=pFrame;
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
//这里要注意 IDR_MAINFRM菜单栏上必须要有两个选择项不然会报错
//打开新文档
OnFileNew();
return 1;
}
程序下载http://pan.baidu.com/s/1qWjnoXe
MFC多文档创建 CMultiDocTemplate CMDIChildWnd CMDIFrameWnd 14.5.5
最新推荐文章于 2021-12-04 22:26:17 发布