我参考书籍和高人的网文,想把一个SDI用CSplitterWnd把它分割为左右两部分
左边和右边都继承于CFormView
这样做的,用class wizard新建了CRightView,CLeftView继承于CFormView(先insert dialog 再class wizard的,CFormView必须要有对应的dialog)
在mainform中改写了OnCreateClient()
if(!m_wndSplitter.CreateStatic(this,1,2,WS_CHILD | WS_VISIBLE))
return false;//不成功就返回

else
{
m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CRightView),CSize(800,700),pContext);
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CLeftView),CSize(100,300),pContext);

m_wndSplitter.SetColumnInfo(0, 230, 10);
m_wndSplitter.RecalcLayout( );
return TRUE;//成功的返回值

编译没有任何错误,执行却错误了
单步调试,问题在于:
m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CRightView),CSize(800,700),pContext);
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CLeftView),CSize(100,300),pContext);
我把以上两句换成
m_wndSplitter.CreateView(0,1,pContext->m_pNewViewClass,CSize(800,700),pContext); m_wndSplitter.CreateView(0,0,pContext->m_pNewViewClass,CSize(100,300),pContext);
结果不是我所想要的CFormView类
请高人指点

解决方案 »

  1.   

    我把以上的程序作了修改
    CRuntimeClass * prt1 = RUNTIME_CLASS( CRightView );
    CRuntimeClass * prt2 = RUNTIME_CLASS( CLeftView ); m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(prt1),CSize(800,700),pContext); m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(prt2),CSize(100,300),pContext);
    发现报错了
    error C2653: 'prt1' : is not a class or namespace name
    error C2065: 'classprt1' : undeclared identifier
    error C2653: 'prt2' : is not a class or namespace name
    error C2065: 'classprt2' : undeclared identifier
    这是为什么??
      

  2.   

    BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
    {
    // TODO: Add your specialized code here and/or call the base class
    // create a splitter with 1 row, 2 columns
    CRect rect;
    long width, height; ShowWindow(SW_SHOWMAXIMIZED);
    GetClientRect(&rect);
    width = rect.right-rect.left;
    height = rect.bottom-rect.top;
    if (!m_wndSplitter.CreateStatic(this, 1, 2,WS_CHILD | WS_VISIBLE))
    {
    TRACE("Failed to CreateStaticSplitter\n");
    return FALSE;
    }
    // First splitter pane
    if (!m_wndSplitter.CreateView(0, 0,
    RUNTIME_CLASS(CMyView), CSize(width-160,height), pContext))
    {
    TRACE("Failed to create command view pane\n");
    return FALSE;
    } if (!m_wndSplitter.CreateView(0, 1,
    RUNTIME_CLASS(CFormCommandView), CSize(160,height), pContext))
    {
    TRACE("Failed to create command view pane\n");
    return FALSE;
    }
    // Second splitter pane

    // return CMDIChildWnd::OnCreateClient(lpcs, pContext);
    return TRUE;
    }看看我的,感觉跟你的有区别。
      

  3.   

    你的CMyView,CFormCommandView是怎么创建的??
      

  4.   

    CMyView,CFormCommandView都是继承CFormView吗??
    具体点怎么搞??
      

  5.   

    CMyView从CView派生的,CFormCommandView是继承CFormView的。
      

  6.   

    那我的怎么不行呢
    我照你的方法重建的工程
    还是不行
    是不是我建的SDI的原因
    BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
    你是BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
    单文档不是也可以吗??
      

  7.   

    我用你的方法
    建的是多文档的工程
    还是不行
    和其它都是一样的错误
    都是建立失败
    类向导
    CMyView从CView派生的,CFormCommandView是继承CFormView
    在BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
    添加你的代码的
      

  8.   

    我解决了
    是要修改dialog属性
    对dialog资源设一下,
    一个是none;
    一个是child;