我做了一个单文档工程,在向导中去掉了view/doc选项,需要把界面分割成一些子窗口,我的做法如下:
...
CSplitterWnd m_wndSplitter;
...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, WS_CHILD))
return FALSE;
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CLeftView),CSize(100,500),pContext);
m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CRightView),CSize(200,200),pContext);
SetActiveView((CView*)m_wndSplitter.GetPane(0,0)); return TRUE;
}
...
这样有问题吗?为什么没有看到分割后的效果?需要怎么做呢?我看CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)函数里面有一段:
if (!m_wndView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
{
TRACE0("Failed to create view window\n");
return -1;
}
是否需要去掉这一段?但我去掉了运行老是出错?不可去掉吗?请大家指点

解决方案 »

  1.   

    还有一个问题,我用ClassWizard从CView派生了一个类,为什么其构造函数是protected?而且加上了DECLARE_DYNCREATE?我在创建分割窗口视图用这个View类可以吗?m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CLeftView),CSize(100,500),pContext);
    我不知道这样可不可以,于是又从CWnd类派生了一个类CTestView, 用它来创建分割窗口视图,结果报错:
    ...
    m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CTestView),CSize(100,500),pContext);
    ...
    Compiling...
    MainFrm.cpp
    D:\workspace\GMTool\Test\MainFrm.cpp(145) : error C2039: 'classCTestView' : is not a member of 'CTestView'
    ...
    为什么会这样?