📄 index182.htm
字号:
<html>
<style type="text/css"><!--
.p9 { font-family: "宋体"; font-size: 9pt}a {text-transform: none; text-decoration: none;}
a:hover {text-decoration: underline; color: #FF0000;}
--></style>
<body background="../di2001.jpg">
<h3 align="center"><font COLOR="#AOAO99"></font></h3>
<table width="100%" border="1" cellspacing="1">
<tr><td><p align="center"><font color="#FF0000">为何MDI程序中有子窗口打开时主应用程序不能关.</font></td></tr>
<tr><td><p>
</Br>
我在MDI程序中增加了一个CRichEditView文档模板,在子窗口视中我增加了下面一些代码.<Br>
StartReport (void)<Br>
{<Br>
CReportFrame *rpt;<Br>
CReportDoc *rptDoc;<Br>
</Br>
// First get the right document template<Br>
POSITION pPos = theApp.GetFirstDocTemplatePosition();<Br>
theApp.GetNextDocTemplate ( pPos );<Br>
theApp.GetNextDocTemplate ( pPos );<Br>
CDocTemplate *pTemplate = theApp.GetNextDocTemplate ( pPos );<Br>
</Br>
// Verify validity<Br>
ASSERT(pTemplate != NULL);<Br>
ASSERT_KINDOF(CDocTemplate, pTemplate);<Br>
</Br>
// Create the frame<Br>
rptDoc = new CReportDoc;<Br>
rpt = (CReportFrame*)pTemplate->CreateNewFrame ( rptDoc, NULL );<Br>
pTemplate->InitialUpdateFrame (rpt, rptDoc);<Br>
</Br>
// Get access to the display area<Br>
CReportView *rptView = static_cast(rpt->GetActiveView());<Br>
CRichEditCtrl &rptCtrl = rptView->GetRichEditCtrl();<Br>
}<Br>
CReportFrame继承于CMDIChildWnd<Br>
CReportDoc继承于CRichEditDoc<Br>
CReportView继承于from CRichEditView<Br>
如果我关闭程序前不关闭新建的视,调试器将认为程序依然在运行(程序管理器中依然存在) 我需要用调试菜单中的stop debugging来关闭程序;如果我手工关闭该视,程序将会正常关闭.如果有什么不同的话,在手工关闭新的视之前程序会询问是否保存. 那么怎样我才能关闭程序呢?<Br>
</Br>
1)我也碰上过对话框,窗口不能自动关闭的情况,这主要是因为继承的对象不正确所造成的。通常应该在主程序中设置AfxGetMainWnd().<Br>
你的程序让我搞糊涂了,一连使用了多个GetNextDocTemplate(pPos),在这些文档指针是NULL时通常会引起一些循环.在你的文档模板中是否已经精心算好了数目?这样可能会产生些bugs 我建议找出当前的文档模板用CDocTemplate::CreateNewDocument()来代替你的"new CReportDoc"<Br>
2) 记住一个公共规则,关闭程序前要关闭所有的视.<Br>
</Br>
</Br>
</p></td></tr>
</table>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -