这是我的一段切换视的代码,但没有切分窗口,希望有所帮助。
void CMainFrame::SwitchToView(CView *pCurrentView, CRuntimeClass *pClass)
{
  CView *pNewView;
  CCreateContext context;  ShowControlBar(&m_wndWordToolBar, FALSE, FALSE);  context.m_pCurrentDoc=pCurrentView->GetDocument();
  context.m_pNewViewClass=pClass;
  pNewView=(CView*)CreateView(&context);
  pNewView->OnInitialUpdate();
  SetActiveView(pNewView);
  RecalcLayout();
  pCurrentView->DestroyWindow();  if (pClass==RUNTIME_CLASS(CDocManArticleView)) {
    ShowControlBar(&m_wndWordToolBar,TRUE,FALSE);
  }
  else if (pClass==RUNTIME_CLASS(CDocManWordView)) {
    ShowControlBar(&m_wndWordToolBarEx, TRUE, FALSE);
  }
}

解决方案 »

  1.   

    我后来将create一句改为:
    pNewActiveView->Create(NULL,NULL,WS_BORDER,rect,&m_wndSplitter1,
    nView,&context);
    rect为左边那个Pane的大小发现可以换,但是换出来的视的大小不对,但是改变窗口大小后正常
    可是再换一次就出现错误提示
      

  2.   

    你为何不用CSplitterWnd去切分视。
      

  3.   

    用了CSplitterWnd呀,我就是要在切分窗口的左半边更换视
      

  4.   

    pOldActiveView->SetDlgCtrlID(pOldActiveView->GetRuntimeClass()== RUNTIME_CLASS(CKeppler) ? IDD_EC_FORM : IDD_KEPPLER_FORM); 
        如果你把CKeppler隐藏了,是不是应该把pOldActiveView的ID设为IDD_KEPPLER_FORM?
      

  5.   

    mSplitterWnd.SetActivePane(...)和mSplitterWnd.GetActivePane(...)参数自己去看msdn吧!
    很简单的!!!!
    :)
      

  6.   

    to gstan:
    不太明白,我要更换视,不是设置那个视为Active呀我按照上面做运行的结果是每次更换时出现错误,当点“忽略”后正确显示,
    但是窗口变小时,好像由于视的大小在创建时固定了,结果分割条在窗口中
    不可见(我用的是FormView)
      

  7.   

    朋友,你运气真好啊,我的程序中正好需要这个功能,我找了半天才在《mfc经典问答中找到这个函数,(我可是照着书一点一点的敲进去的呀,呜呜),你粘过去吧,应该是可以的,我的程序就是这么做的,不过做到最后发现左边的formview的功能都可以通过菜单项实现,所以变成了鸡肋了,呵呵void EkSwitchViewInSplitter(CMySplitterWnd *pSplitter, int row, int col, CRuntimeClass *pViewClass)
    {
    ASSERT_VALID( pSplitter );
    ASSERT( pViewClass != NULL );
    ASSERT( pViewClass->IsDerivedFrom( RUNTIME_CLASS( CView ) ) );
    //查找要替换的视图
    CWnd* pPaneWnd = pSplitter->GetPane( row,col );
    if( !pPaneWnd->IsKindOf( RUNTIME_CLASS( CView ) ) )
    {
    TRACE2
    ("Unable to switch: pane (%d,%d) is not a view\n",row,col);

    return;
    } CView* pCurrentView = static_cast<CView*> (pPaneWnd);
    ASSERT_VALID( pCurrentView );
    ASSERT_KINDOF( CView,pCurrentView ); if(pCurrentView->IsKindOf(pViewClass))
    {
    return;
    }
    //保存当前视图的位置和活动状态
    CRect rcView;
    pCurrentView->GetWindowRect( &rcView ); CView* pActiveView = pSplitter->GetParentFrame()->GetActiveView();
    BOOL bSaveActive = ( pActiveView == NULL ) || (pActiveView == pCurrentView );
    //查找相关的文档
    CDocument* pDoc = pCurrentView->GetDocument();
    ASSERT_VALID( pDoc);
    //当释放活动窗口时,确保文档不会自我析构
    BOOL bSaveAutoDelete = pDoc->m_bAutoDelete;
    pDoc->m_bAutoDelete = FALSE;
    //释放活动视图
     pCurrentView->DestroyWindow();
     //恢复文档到初始状态
     pDoc->m_bAutoDelete = bSaveAutoDelete;
     //初始化CreatView()使用的创建上下文
     CCreateContext context;
     context.m_pNewDocTemplate = NULL;
     context.m_pLastView = NULL;
     context.m_pCurrentFrame = NULL;
     context.m_pNewViewClass = pViewClass;
     context.m_pCurrentDoc = pDoc;
     //创建新的视图
     pSplitter->CreateView( row,col,pViewClass,rcView.Size(),&context );
     CView* pNewView = static_cast<CView*>(pSplitter->GetPane( row,col ));
     ASSERT_VALID( pNewView );
     ASSERT_KINDOF( CView, pNewView );
     //定位新视图,与旧视图位置相同,如果需要则激活它
     pSplitter->ScreenToClient( &rcView );
     pNewView->MoveWindow( &rcView, TRUE );
     if( bSaveActive )
     {
    pSplitter->GetParentFrame()->SetActiveView( pNewView );
     }
     //给视图发送WM_INITIALUPDATE
     pNewView->GetParentFrame()->InitialUpdateFrame( pDoc,TRUE );
    }
      

  8.   

    class CExSplitterWnd : public CSplitterWnd
    {
    // Construction
    public:
        CExSplitterWnd();
    // Overrides
        // ClassWizard generated virtual function overrides
        //{{AFX_VIRTUAL(CExSplitterWnd)
        //}}AFX_VIRTUAL
    // Implementation
        virtual ~CExSplitterWnd();
        BOOL AttachView(CWnd* pView, int row, int col);
        BOOL DetachView(int row, int col);
        // Generated message map functions
        //{{AFX_MSG(CExSplitterWnd)
            // NOTE - the ClassWizard will add and remove member functions here.
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
    };
    CExSplitterWnd::CExSplitterWnd()
    {
    }
    CExSplitterWnd::~CExSplitterWnd()
    {
    }
    BOOL CExSplitterWnd::AttachView(CWnd* pView, int row, int col)
    {
        //Make sure the splitter window was created
        if (!IsWindow(m_hWnd))
        {
            ASSERT(0);
            TRACE(_T("Create the splitter window before attaching windows to panes"));
            return (FALSE);
        }    //Make sure the row and col indices are within bounds
        if (row >= GetRowCount() || col >= GetColumnCount())
        {
            ASSERT(0);
            return FALSE;
        }    //Is the window to be attached a valid one
        if (pView == NULL || (!IsWindow(pView->m_hWnd)))
        {
            ASSERT(0);
            return FALSE;
        }    pView->SetDlgCtrlID(IdFromRowCol(row, col));
        pView->SetParent(this);
        pView->ShowWindow(SW_SHOW);
        pView->UpdateWindow();
        return (TRUE);
    }
    BOOL CExSplitterWnd::DetachView(int row, int col)
    {
        //Make sure the splitter window was created
        if (!IsWindow(m_hWnd))
        {
            ASSERT(0);
            TRACE(_T("Create the splitter window before attaching windows to panes"));
            return (FALSE);
        }
        //Make sure the row and col indices are
        //within bounds
        if (row >= GetRowCount() || col >= GetColumnCount())
        {
            ASSERT(0);
            return FALSE;
        }
        CWnd* pWnd = GetPane(row, col);
        if (pWnd == NULL || (!IsWindow(pWnd->m_hWnd)))
        {
            ASSERT(0);
            return FALSE;
        }
        pWnd->ShowWindow(SW_HIDE);
        pWnd->UpdateWindow();
        //Set the parent window handle to NULL so that this child window is not
        //destroyed when the parent (splitter) is destroyed
        pWnd->SetParent(NULL);
        return (TRUE);
    }
      

  9.   

    To killlaoli:
    非常感谢,这个真的很好使,另外请问一下《MFC经典问答》是一个什么书
    To hnyyy:
    使用你的这个类时,我们此new一个FormView的指针,然后把它作为参数传给
    Attach,但是debug时发现m_hWnd为NULL,请问new了以后,还用进行那些设置?先给出一些分吧!
      

  10.   

    <<MFC经典问答>>/(美)凯恩编住;健莲科技译,北京中国电力出版社,2001年7月第一版,定价:59.00元
    该书收集了mfc编程中经常遇到的问题,多达130多条,很不错的,适合我这种菜鸟,嘿嘿