看如下CFrameWnd::OnClose()函数: void CFrameWnd::OnClose() { //判断是否由嵌入Frame,如OleFrame, 打印预览等. if (m_lpfnCloseProc != NULL && !(*m_lpfnCloseProc)(this)) return; // Note: only queries the active document CDocument* pDocument = GetActiveDocument(); //通知文档,判断是否是最后一个文档关联的窗口,并且文档允许 //如果没有存盘,CanCloseFrame函数会弹出窗口询问是否存盘 if (pDocument != NULL && !pDocument->CanCloseFrame(this)) { // document can't close right now -- don't close it return; } //如果是主窗口,可能要结束进程. CWinApp* pApp = AfxGetApp(); if (pApp != NULL && pApp->m_pMainWnd == this) { // attempt to save all documents if (pDocument == NULL && !pApp->SaveAllModified()) return; // don't close it // hide the application's windows before closing all the documents pApp->HideApplication(); // close all documents first pApp->CloseAllDocuments(FALSE); // don't exit if there are outstanding component objects if (!AfxOleCanExitApp()) { // take user out of control of the app AfxOleSetUserCtrl(FALSE); // don't destroy the main window and close down just yet // (there are outstanding component (OLE) objects) return; } // there are cases where destroying the documents may destroy the // main window of the application. if (!afxContextIsDLL && pApp->m_pMainWnd == NULL) { AfxPostQuitMessage(0); return; } } // detect the case that this is the last frame on the document and // shut down with OnCloseDocument instead. // 如果关联的文档有效,并且是自动删除的. if (pDocument != NULL && pDocument->m_bAutoDelete) { BOOL bOtherFrame = FALSE; POSITION pos = pDocument->GetFirstViewPosition(); while (pos != NULL) { CView* pView = pDocument->GetNextView(pos); ASSERT_VALID(pView); if (pView->GetParentFrame() != this) { bOtherFrame = TRUE; break; } } //与文档关联的最后一个Frame被关闭,关闭文档. if (!bOtherFrame) { pDocument->OnCloseDocument(); return; } // allow the document to cleanup before the window is destroyed pDocument->PreCloseFrame(this); } // then destroy the window DestroyWindow(); }因此,将pDocument->m_bAutoDelete = FALSE, 就不会导致文档的自动删除. 但是你自己要注意显示删除它
void CFrameWnd::OnClose()
{
//判断是否由嵌入Frame,如OleFrame, 打印预览等.
if (m_lpfnCloseProc != NULL && !(*m_lpfnCloseProc)(this))
return; // Note: only queries the active document
CDocument* pDocument = GetActiveDocument();
//通知文档,判断是否是最后一个文档关联的窗口,并且文档允许
//如果没有存盘,CanCloseFrame函数会弹出窗口询问是否存盘
if (pDocument != NULL && !pDocument->CanCloseFrame(this))
{
// document can't close right now -- don't close it
return;
}
//如果是主窗口,可能要结束进程.
CWinApp* pApp = AfxGetApp();
if (pApp != NULL && pApp->m_pMainWnd == this)
{
// attempt to save all documents
if (pDocument == NULL && !pApp->SaveAllModified())
return; // don't close it // hide the application's windows before closing all the documents
pApp->HideApplication(); // close all documents first
pApp->CloseAllDocuments(FALSE); // don't exit if there are outstanding component objects
if (!AfxOleCanExitApp())
{
// take user out of control of the app
AfxOleSetUserCtrl(FALSE); // don't destroy the main window and close down just yet
// (there are outstanding component (OLE) objects)
return;
} // there are cases where destroying the documents may destroy the
// main window of the application.
if (!afxContextIsDLL && pApp->m_pMainWnd == NULL)
{
AfxPostQuitMessage(0);
return;
}
} // detect the case that this is the last frame on the document and
// shut down with OnCloseDocument instead.
// 如果关联的文档有效,并且是自动删除的.
if (pDocument != NULL && pDocument->m_bAutoDelete)
{
BOOL bOtherFrame = FALSE;
POSITION pos = pDocument->GetFirstViewPosition();
while (pos != NULL)
{
CView* pView = pDocument->GetNextView(pos);
ASSERT_VALID(pView);
if (pView->GetParentFrame() != this)
{
bOtherFrame = TRUE;
break;
}
}
//与文档关联的最后一个Frame被关闭,关闭文档.
if (!bOtherFrame)
{
pDocument->OnCloseDocument();
return;
} // allow the document to cleanup before the window is destroyed
pDocument->PreCloseFrame(this);
} // then destroy the window
DestroyWindow();
}因此,将pDocument->m_bAutoDelete = FALSE, 就不会导致文档的自动删除. 但是你自己要注意显示删除它
关闭一个可以 view->childframe->close.
不明白你要做什么。