我在MDI应用程序中打开了MFC CDocument和关联的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 ++。
答案 0 :(得分:1)
如果将CDocument :: m_bAutoDelete设置为FALSE(在创建文档之后),则在最后一个视图关闭时不应删除该文档。
我不确定你特意尝试做什么,但你可能想要考虑创建一个单独的'数据'对象,它可以附加到文档而不是试图保持文档本身。