截获MDI tab 的关闭按钮事件:
重载ChildFrame的OnClose函数,在其中拦截关闭事件。
例子:在其中判断是否是最后一个View,如果是最后一个,则关闭之前创建一个新的View,确保文档对象不被关闭。
创建新View可以重载ChildFrame的OnWindowNew函数:
OnWindowNew
void CGraphFrame::OnWindowNew() { CMainFrame* pMainFrame = (CMainFrame*) AfxGetMainWnd(); CDocument* pDoc=pMainFrame->MDIGetActive()->GetActiveDocument(); pMainFrame->CreateNewView(IDI_CLASS_VIEW, RUNTIME_CLASS(CGraphFrame),RUNTIME_CLASS(CGraphExView),pDoc); //CMDIFrameWnd::OnWindowNew(); }
重载OnClose函数:
OnClose
void CGraphFrame::OnClose() { // TODO: Add your message handler code here and/or call default CGraphExDoc* pDoc = dynamic_cast<CGraphExDoc*>( GetActiveDocument() ); POSITION pos = pDoc->GetFirstViewPosition(); int nView=0; while(pDoc->GetNextView(pos)) { nView++; } if( nView==1 ) { OnWindowNew(); CGraphExView* pView = dynamic_cast<CGraphExView*>( GetActiveView() ); SetActiveView(pView); } CMDIChildWndEx::OnClose(); }

浙公网安备 33010602011771号