15,979
社区成员
发帖
与我相关
我的任务
分享
void CMainFrame::OnSwitchToSecond()
{
m_wndSplitter.DeleteView(0,1);
m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CSecondView), CSize(0,0),NULL);
m_wndSplitter.RecalcLayout();
}
CLeftPaneView* pLeftPaneView = (CLeftPaneView*) m_wndSplitter.GetPane(0,0);
pLeftPaneView->m_pRightPaneFrame = (CRightPaneFrame*) m_wndSplitter.GetPane(0,1);
// Set the left pane as the active view
SetActiveView((CView*) m_wndSplitter.GetPane(0, 0));
// Attributes
public:
CSplitterView* m_pSplitterView;
CListCtrlView* m_pListCtrlView;
CEditCtrlView* m_pEditCtrlView;
UINT m_nCurrentViewID;
BOOL CRightPaneFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
m_pSplitterView = new CSplitterView;
m_pSplitterView->Create(NULL, NULL, 0L, CFrameWnd::rectDefault, this, VIEW_SPLITTER, pContext);
SetActiveView(m_pSplitterView);
m_pSplitterView->ShowWindow(SW_SHOW);
m_pSplitterView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
m_nCurrentViewID = VIEW_SPLITTER;
m_pListCtrlView = new CListCtrlView;
((CView*) m_pListCtrlView)->Create(NULL, NULL, 0L, CFrameWnd::rectDefault, this, VIEW_LISTCTRL, pContext);
m_pListCtrlView->ShowWindow(SW_HIDE);
m_pListCtrlView->SetDlgCtrlID(VIEW_LISTCTRL);
m_pEditCtrlView = new CEditCtrlView;
((CView*) m_pEditCtrlView)->Create(NULL, NULL, 0L, CFrameWnd::rectDefault, this, VIEW_EDIT, pContext);
m_pEditCtrlView->ShowWindow(SW_HIDE);
m_pEditCtrlView->SetDlgCtrlID(VIEW_EDIT);
RecalcLayout();
return TRUE;
}
void CRightPaneFrame::SwitchToView(UINT nView)
{
CView* pOldActiveView = GetActiveView();
CView* pNewActiveView = NULL;
switch (nView)
{
case VIEW_SPLITTER:
pNewActiveView = (CView*) m_pSplitterView;
break;
case VIEW_LISTCTRL:
pNewActiveView = (CView*) m_pListCtrlView;
break;
case VIEW_EDIT:
pNewActiveView = (CView*) m_pEditCtrlView;
break;
}
if (pNewActiveView)
{
// don't switch when views are the same
if (pOldActiveView == pNewActiveView) return;
SetActiveView(pNewActiveView);
pNewActiveView->ShowWindow(SW_SHOW);
pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
pOldActiveView->ShowWindow(SW_HIDE);
pOldActiveView->SetDlgCtrlID(m_nCurrentViewID);
m_nCurrentViewID = nView;
RecalcLayout();
}
}
//
BOOL CMainFrame::ChangeView(CRuntimeClass *pNewViewClass)
{
CCreateContext Context;// I hate 'new'
ZeroMemory(&Context,sizeof(Context));
Context.m_pCurrentFrame=this;
Context.m_pCurrentDoc=GetActiveDocument();
//
CRect rect;
GetClientRect(&rect);
CSize size=rect.Size();
size.cx /= 2;// col
size.cy /= 3;// row
//
int Row,Col;
m_wndSplitter2.LockWindowUpdate();
//
m_wndSplitter2.GetActivePane(&Row,&Col);
m_wndSplitter2.DeleteView(Row,Col);// focus move to next !
m_wndSplitter2.CreateView(Row,Col,pNewViewClass,size,&Context);
m_wndSplitter2.RecalcLayout();
// send 'InitialUpdate' to view
InitialUpdateFrame(NULL,TRUE);
// no flush
m_wndSplitter2.SetActivePane(Row,Col);
//
m_wndSplitter2.UnlockWindowUpdate();
//
return TRUE;
}