现在的位置: 首页 > 综合 > 正文

SDI到MDI的转换

2018年06月07日 ⁄ 综合 ⁄ 共 1733字 ⁄ 字号 评论关闭

 

新MDI程序可以使用与原SDI同样的文档和视图发爱马,以及同样的资源(除了程序名以外)。但应用程序代码和主框架类代码是不同的。
步骤:
1.         修改应用程序类InitInstance()函数中的文档模板,并创建MDI框架窗口:
       CMultiDocTemplate* pDocTemplate;
       pDocTemplate = new CMultiDocTemplate(
              IDR_MY16BTYPE,                 //MY16B是工程名
              RUNTIME_CLASS(CMy16bDoc),
              RUNTIME_CLASS(CChildFrame),       // custom MDI Child frame
              RUNTIME_CLASS(CMy16bView));
       AddDocTemplate(pDocTemplate);
//create main MDI frame window
       CMainFrame* pMainFrame = new CMainFrame;
       if(!pMainFrame->LoadFrame(IDR_MAINFRAME))
              return FALSE;
       m_pMainWnd = pMainFrame;
并在ParseCommandLine(cmdInfo);后添加如下代码:
       //no empty document window on startup
       if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew)
       {
              cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
       }
2.         修改CMainFrame类,它几乎和SDI版本完全一样,除了它是CMDIFrameWnd而不是CFrameWnd派生出来的。
3.         添加派生自CMDIChildWnd的子框架类。这似的用户可以通过在PreCreateWindow()函数中添加代码方便的控制子框架窗口的属性。也可以映射消息和重载其他的虚拟函数。
 
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
       // TODO: Add your specialized code here and/or call the base class
       if (!CMDIChildWnd::PreCreateWindow(cs))
            return FALSE;
       return TRUE;
      
      
       return CMDIChildWnd::PreCreateWindow(cs);
}
 
void CChildFrame::ActivateFrame(int nCmdShow)
{
       // TODO: Add your specialized code here and/or call the base class
      
       CMDIChildWnd::ActivateFrame(nCmdShow);
}
 
 
#ifdef _DEBUG
void CChildFrame::AssertValid() const
{
       CMDIChildWnd::AssertValid();
}
 
void CChildFrame::Dump(CDumpContext& dc) const
{
       CMDIChildWnd::Dump(dc);
}
 
#endif //_DEBUG
 
4.         修改字符串表
添加新项ID为IDR_MY16BTYPE,值为:
My16b/n新建文档/nMy16b/n.17a/n.17a/nMy16b.Document/n17a Document

 


http://blog.csdn.net/qlping2007/article/details/2128339

抱歉!评论已关闭.