MDI,SDI创建过程中的一点不同--发布日期:2007-8-31

来源:互联网 发布:良剑期乎断 不期乎镆铘 编辑:程序博客网 时间:2024/04/28 14:34

CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
   IDR_MDISQUTYPE,
   RUNTIME_CLASS(CSquaresDoc),
   RUNTIME_CLASS(CChildFrame), // custom MDI child frame
   RUNTIME_CLASS(CSquaresView));
AddDocTemplate(pDocTemplate);

// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
   return FALSE;
m_pMainWnd = pMainFrame;

。。。。。。。。

   // Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
   return FALSE;

// The main window has been initialized, so show and update it.
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();

上面为MDI,下面为SDI

CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
   IDR_MAINFRAME,
   RUNTIME_CLASS(CSquaresDoc),
   RUNTIME_CLASS(CMainFrame),       // main SDI frame window
   RUNTIME_CLASS(CSquaresView));
AddDocTemplate(pDocTemplate);

。。。。。。。。。。

// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
   return FALSE;


// The main window has been initialized, so show and update it.
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();

主要是在生产文档模板对象时RUNTIME_CLASS(CChildFrame), // custom MDI child frame
VS RUNTIME_CLASS(CMainFrame),       // main SDI frame window
MDI传递的是childframe,而SDI传递的mainframe,因此MDI的ProcessShellCommand创建的是ChildFrame而SDI创建的MainFrame,所以MDI中就多出了

// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
   return FALSE;
m_pMainWnd = pMainFrame;

必须自己创建MainFrame.

原创粉丝点击