我在一个CDocument应用程序中打开了一个MFC和相关的CView。我想分离并关闭视图(和关联的框架),同时保持文档打开。环顾MFC代码,看看它是如何做到的,在CDocument::OnCloseDocument()中揭示了以下内容;
// destroy all frames viewing this document
// the last destroy may destroy us
BOOL bAutoDelete = m_bAutoDelete;
m_bAutoDelete = FALSE; // don't destroy document while closing views
while (!m_viewList.IsEmpty())
{
// get frame attached to the view
CView* pView = (CView*)m_viewList.GetHead();
ASSERT_VALID(pView);
CFrameWnd* pFrame = pView->EnsureParentFrame();
// and close it
PreCloseFrame(pFrame);
pFrame->DestroyWindow();
// will destroy the view as well
}
m_bAutoDelete = bAutoDelete;我想我可以和CDocument::RemoveView一起使用。有没有比仅仅提升MFC源代码更好的方法呢?这种方法会给我带来其他问题或副作用吗?该项目是VS2010 C++。
发布于 2012-11-09 18:23:42
如果将CDocument::m_bAutoDelete设置为FALSE (在创建文档之后),则不应在最后一个视图关闭时删除文档。
我不确定你到底想做什么,但你可能想要考虑创建一个单独的'data‘对象,这个对象可以附加到文档上,而不是试图保留文档本身。
https://stackoverflow.com/questions/13305907
复制相似问题