不知道题目说明白没有。我的程序有点像Outlook:
Outlook点击左面的OutlookBar的按纽可以在右面的框架中切换视图,比如点击Outlook Today,右面会显示单一的视图,但是如果点击邮件夹Index,右面就会显示切分窗口,上面是ListView,下面是个CView,也就是说我想在运行时动态创建切分视图和动态切换视图。我知道有一个CMainFrame::SwitchToView的例子,但是那个只能切换单一的视,不能把视图1换成由视图2和视图3组成的切分窗口或换回来。请首长指示。
Outlook点击左面的OutlookBar的按纽可以在右面的框架中切换视图,比如点击Outlook Today,右面会显示单一的视图,但是如果点击邮件夹Index,右面就会显示切分窗口,上面是ListView,下面是个CView,也就是说我想在运行时动态创建切分视图和动态切换视图。我知道有一个CMainFrame::SwitchToView的例子,但是那个只能切换单一的视,不能把视图1换成由视图2和视图3组成的切分窗口或换回来。请首长指示。
例如你的切分窗口是
CSplitterWnd m_Dynwnd;
你在ChildFrame的OnCreateClient里不要用m_Dynwnd.CreateStatic和m_Dynwnd.CreateView,
而要用Create,因为需要动态切分。在你要切分的地方用SplitColumn或者SplitRow来动态切分。不过好像最多只能
动态切分成4个窗口。
http://61.133.87.165/bbs/attachment.php?s=&postid=432958
给你一段代码,这个例子说明了如何在两个视之间切换
BOOL CMainFrame::OnViewChange(UINT nCmdID)
// There is an ON_COMMAND_RANGE message map entry associated with
// OnViewChange:
// ON_COMMAND_RANGE( ID_VIEW_VIEW1, ID_VIEW_VIEW2, OnViewChange)
{
CView* pViewAdd;
CView* pViewRemove;
CDocument* pDoc = GetActiveDocument(); if((nCmdID == ID_VIEW_VIEW1) && (m_currentView == 1))
return;
if((nCmdID == ID_VIEW_VIEW2) && (m_currentView == 2))
return; if (nCmdID == ID_VIEW_VIEW2)
{
if (m_pView2 == NULL)
{
m_pView1 = GetActiveView();
m_pView2 = new CMyView2;//Note that if OnSize has been overridden in CMyView2
//and GetDocument() is used in this override it can
//cause assertions and, if the assertions are ignored,
//cause access violation.
m_pView2->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
rectDefault, this, AFX_IDW_PANE_FIRST + 1, NULL);
}
pViewAdd = m_pView2;
pViewRemove = m_pView1;
m_currentView= 2;
}
else
{
pViewAdd = m_pView1;
pViewRemove = m_pView2;
m_currentView= 1;
}
// Set the child i.d. of the active view to AFX_IDW_PANE_FIRST,
// so that CFrameWnd::RecalcLayout will allocate to this
// "first pane" that portion of the frame window's client area
// not allocated to control bars. Set the child i.d. of the
// other view to anything other than AFX_IDW_PANE_FIRST; this
// examples switches the child id's of the two views. int nSwitchChildID = pViewAdd->GetDlgCtrlID();
pViewAdd->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
pViewRemove->SetDlgCtrlID(nSwitchChildID); // Show the newly active view and hide the inactive view. pViewAdd->ShowWindow(SW_SHOW);
pViewRemove->ShowWindow(SW_HIDE); // Connect the newly active view to the document, and
// disconnect the inactive view.
pDoc->AddView(pViewAdd);
pDoc->RemoveView(pViewRemove); SetActiveView(pViewAdd);
RecalcLayout();
}
http://www.codeguru.com/mfc/comments/7113.shtml