MFC单文档启动时不新建文档问题

2009年04月16日 星期四 14:53

今天有个当文档工程,在启动时不要新建文档的需求。

搜索了半天,发现网上的说的解决方法都是针对多文档才有效,针对单文档就有问题了。

debug模式下,跑到:

// The one and only window has been initialized, so show and update it
m_pMainWnd->ShowWindow(SW_SHOW);
   m_pMainWnd->UpdateWindow();

就出现Bug了。

其实debug模式下可以看到m_pMainWnd的值是0,这明显是有问题的。

所以执行到函数体:

BOOL CWnd::ShowWindow(int nCmdShow)
{
ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));

if (m_pCtrlSite == NULL)
   return ::ShowWindow(m_hWnd, nCmdShow);
else
   return m_pCtrlSite->ShowWindow(nCmdShow);
}

就有问题了!

附上多文档的解决方法:

CCommandLineInfo cmdInfo;
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;//加入的code
ParseCommandLine(cmdInfo);

posted on 2010-09-20 16:19  xilentz  阅读(1695)  评论(0编辑  收藏  举报