这个功能,意思是一个文档类可以在多个视窗类中使用。所以我们首先得要有多个视窗。
在建立多文档程序时,只有一个视窗类。
我们自己再新建一个,然后实现这两个视窗共同使用一个文档类
主要是在APP类的InitInstance函数内实现
- BOOL CMy123App::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_MY123TYPE,
- RUNTIME_CLASS(CMy123Doc),
- RUNTIME_CLASS(CChildFrame), // custom MDI child frame
- RUNTIME_CLASS(CMy123View));
- AddDocTemplate(pDocTemplate);
- //创建文档模板2
- CMultiDocTemplate* pDocTemplate2;
- pDocTemplate2 = new CMultiDocTemplate(
- IDR_MY123TYPE,
- RUNTIME_CLASS(CMy123Doc),
- RUNTIME_CLASS(CChildFrame),
- RUNTIME_CLASS(CDemoView));
- AddDocTemplate(pDocTemplate2);
-
- // create main MDI Frame window
- CMainFrame* pMainFrame = new CMainFrame;
- if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
- return FALSE;
- m_pMainWnd = pMainFrame;
- // 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;
- */
- //文档模板1新建一个文档
- CMy123Doc* pDoc = (CMy123Doc*)pDocTemplate->OpenDocumentFile(NULL);
- if (pDoc == NULL)
- {
- return FALSE;
- }
- //文档模板2创建与文档相关联的框架窗口
- CFrameWnd* pFrame = pDocTemplate2->CreateNewFrame(pDoc, NULL);
- if (pFrame == NULL)
- {
- return FALSE;
- }
- //文档模板2初始化框架窗口
- pDocTemplate2->InitialUpdateFrame(pFrame, pDoc);
- //水平排列窗口
- pMainFrame->MDITile(MDITILE_HORIZONTAL);
-
- // The main window has been initialized, so show and update it.
- pMainFrame->ShowWindow(m_nCmdShow);
- pMainFrame->UpdateWindow();
- return TRUE;
- }
复制代码
也可源代码查看
上位机VC MFC程序开发精典实例大全源码与视频讲解配套下载408例 经历1年的编程与录制点击进入查看
|