帮帮忙!MDI里文档和视的苦恼问题!
Newor 2003-03-22 10:40:30 我的MDI里定义两个视图类,单文档。我想程序运行时始终打开这两个视图,并能切换这两个视图的焦点,怎么办?
在Jorge Lodos的下面代码中,切换时只能替换原来的视图,没有切换。
CView* CMyDocument::SwitchToView(CView* pNewView)
{
CMDIFrameWnd* pMainWnd = (CMDIFrameWnd*)AfxGetMainWnd();
// Get the active MDI child window.
CMDIChildWnd* pChild = (CMDIChildWnd*)pMainWnd->MDIGetActive();
// Get the active view attached to the active MDI child window.
CView* pOldActiveView = pChild->GetActiveView();
// Set flag so that document will not be deleted when view is dettached.
BOOL bAutoDelete = m_bAutoDelete;
m_bAutoDelete = FALSE;
// Dettach existing view
RemoveView(pOldActiveView);
// restore flag
m_bAutoDelete = bAutoDelete;
// Show the newly active view and hide the inactive view.
pNewView->ShowWindow(SW_SHOW);
pOldActiveView->ShowWindow(SW_HIDE);
// Attach new view
AddView(pNewView);
pChild->RecalcLayout();
pNewView->UpdateWindow();
pChild->SetActiveView(pNewView);
return pOldActiveView;
}
大家帮忙看看:http://www.codetools.com/docview/switchingviews.asp