SDI到MDI的转换

 
新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
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值