subject_21440.htm

来自「一些关于vc的问答」· HTM 代码 · 共 42 行

HTM
42
字号
<p>
序号:21440 发表者:木子 发表日期:2002-11-17 16:06:58
<br>主题:出现两个Mainframe
<br>内容:我在写程序的时候新创建了一个窗口,但在运行时老是出现两个窗口,一个是新创的,一个是wizard创建的。<BR>代码如下<BR>CSingleDocTemplate* pDocTemplate;<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDocTemplate = new CSingleDocTemplate(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IDR_MAINFRAME,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RUNTIME_CLASS(CChinaBankDoc),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RUNTIME_CLASS(CMainFrame),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // main SDI frame window<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RUNTIME_CLASS(CChinaBankView));<BR>&nbsp;&nbsp;&nbsp;&nbsp;AddDocTemplate(pDocTemplate);<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;// Parse command line for standard shell commands, DDE, file open<BR>&nbsp;&nbsp;&nbsp;&nbsp;CCommandLineInfo cmdInfo;<BR>&nbsp;&nbsp;&nbsp;&nbsp;ParseCommandLine(cmdInfo);<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;// Dispatch commands specified on the command line<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (!ProcessShellCommand(cmdInfo))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return FALSE;<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;// The one and only window has been initialized, so show and update it.<BR>//////创建窗口////////////////////////////////////////////////////////////<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;CMainFrame* pFrame = new CMainFrame;<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (!pFrame-&gt;LoadFrame(IDR_MAINFRAME))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return FALSE;<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;m_pMainWnd = pFrame;<BR>我第一次试着把创建窗口以上的部分删掉,但这样在新的窗口中没有视图,请高手指教!
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:未出手的飞刀 回复日期:2002-11-17 16:38:20
<br>内容:<BR>你的程序里有 ProcessShellCommand(cmdInfo));是不是?那好,我们看ProcessShellCommand是怎么样实现的<BR><BR>BOOL CWinApp::ProcessShellCommand(CCommandLineInfo&amp; rCmdInfo)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;BOOL bResult = TRUE;<BR>&nbsp;&nbsp;&nbsp;&nbsp;switch (rCmdInfo.m_nShellCommand)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;case CCommandLineInfo::FileNew:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!AfxGetApp()-&gt;OnCmdMsg(ID_FILE_NEW, 0, NULL, NULL))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...上面这句产生了窗口<BR><BR>修改方法:<BR>你把<BR>if (!ProcessShellCommand(cmdInfo))<BR>&nbsp;&nbsp; return FALSE;<BR>删除,加上<BR>if(!AfxGetApp()-&gt;OnCmdMsg(ID_FILE_NEW, 0, NULL, NULL))<BR>&nbsp;&nbsp;&nbsp;&nbsp;return FALSE ;<BR>就行了<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:木子 回复日期:2002-11-18 19:17:55
<br>内容:谢谢楼上这位,但我在运行时还是出现两个主窗口,新窗口没有视图
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:未出手的飞刀 回复日期:2002-11-19 00:11:23
<br>内容:////////////////////////////////////////////<BR>&nbsp;&nbsp;&nbsp;&nbsp;CMainFrame* pFrame = new CMainFrame;<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (!pFrame-&gt;LoadFrame(IDR_MAINFRAME))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return FALSE;<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;m_pMainWnd = pFrame;<BR>////////////////////////////////<BR><BR>你这样创建框架是不合sdi常规的,要不你这样<BR>//&nbsp;&nbsp;&nbsp;&nbsp;if (!ProcessShellCommand(cmdInfo))<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return FALSE;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;m_pMainWnd = (CMainFrame*)pDocTemplate-&gt;CreateNewFrame(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pDocTemplate-&gt;CreateNewDocument(),NULL) ;<BR><BR>就是删除原来的创建代码,加上自己的,就一条语句<BR>&nbsp;&nbsp;&nbsp;&nbsp;m_pMainWnd = (CMainFrame*)pDocTemplate-&gt;CreateNewFrame(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pDocTemplate-&gt;CreateNewDocument(),NULL) ;<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:木子 回复日期:2002-11-19 16:06:10
<br>内容:再问一下,那我怎样把视图加入程序呢?<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:未出手的飞刀 回复日期:2002-11-19 19:09:09
<br>内容:<BR>如果不是万不得以,视图一般调用一些框架函数自动创建,如<BR>&nbsp;&nbsp;m_pMainWnd = (CMainFrame*)pDocTemplate-&gt;CreateNewFrame(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pDocTemplate-&gt;CreateNewDocument(),NULL) ;<BR><BR>如果象你那样自己new了一个frame出来,好象可以用CFrameWnd::CreateView来创建视图,但我没试过,<BR>你可以自己探索一下
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:木子 回复日期:2002-11-19 21:07:55
<br>内容:在此多谢了!!!!!!!<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?