rivard
rivard
2016-01-22 08:44

MFC单文档视图 窗口分割 如何切换视图

  • mfc窗口切换视图

图片说明
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
if(!m_wndSplitter.CreateStatic(this,1,2))
return FALSE;
if(!m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CLeftPaneView),CSize(100,100),pContext))
return FALSE;
if(!m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CEditPaneView),CSize(100,100),pContext))
return FALSE;

m_pEditView = (CEditPaneView*)m_wndSplitter.GetPane(0,1);

return TRUE;

}

switch(nViewType)
{
case EDITVIEW:      //CEditPaneView
    {
        if(!pView->IsKindOf(RUNTIME_CLASS(CEditPaneView)))
        {
            //删除旧的视图
            m_wndSplitter.DeleteView(0,1);
            /*CWnd *pWnd=m_wndSplitter.GetPane(0,1);
            (m_wndSplitter.GetPane(0,1))->ShowWindow(SW_HIDE);*/
            //创建新的视图
            m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CEditPaneView),
                CSize(rcRight.Width(),rcRight.Height()),NULL);
            //调整分布
            m_wndSplitter.RecalcLayout();
            m_pEditView= (CEditPaneView*)m_wndSplitter.GetPane(0,1);
        }
        break;
    }
case LISTVIEW:  //CListPaneView
    {
        if(!pView->IsKindOf(RUNTIME_CLASS(CListPaneView)))
        {
            m_wndSplitter.DeleteView(0,1);
            m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CListPaneView),
                CSize(rcRight.Width(),rcRight.Height()),NULL);
            m_wndSplitter.RecalcLayout();
            m_pListView= (CListPaneView*)m_wndSplitter.GetPane(0,1);
        }
        break;
    }
default:
    break;
}


上面是部分代码,主要是想实现1-窗口分割,2-分割后的子窗口进行不同视图的显示;
查了资料,网上都是给出的删除再重新建立视图的做法,如上面示例,请问大家有没有遇到类似的问题,都是如何解决的呢,谢谢!
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐