CSplitterWnd有两个窗格:左窗格是CTreeView,右边是CFrameWnd:无法在右窗格中设置不同的视图

时间:2011-03-09 22:27:32

标签: visual-c++ mfc multiple-views csplitterwnd

我正在尝试实现经典的Windows资源管理器类型的应用程序, CpliterWnd有两个窗格:左窗格是CLeftTreeView:public CTreeView 右侧窗格是CRightPaneFrame:public CFrameWnd,CRightPaneFrame有一个成员变量m_pCustomView。

CustomView是我添加到对话框资源的类(使用资源编辑器和添加类向导编辑)

class CustomView : public CFormView
{

DECLARE_DYNCREATE(CustomView)

public:  // Changed to public so that i can instantiate this view on heap
CustomView();           // protected constructor used by dynamic creation
virtual ~CustomView();
BOOL Create(LPCTSTR A, LPCTSTR B, DWORD C,
    const RECT& D, CWnd* E, UINT F, CCreateContext* G); // To override the protected specifier of CFormView::Create()

MainFrame.cpp具有以下条目

if (!m_SplitterWnd.CreateView(0, 0, RUNTIME_CLASS(CLeftTreeView), CSize(125, 100),   pContext) ||  !m_SplitterWnd.CreateView(0, 1, RUNTIME_CLASS(CRightPaneFrame), CSize(100, 100), pContext))    
{
     m_SplitterWnd.DestroyWindow();
     return FALSE;
}

稍后在CRightPaneFrame中

BOOL CRightPaneFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
    // TODO: Add your specialized code here and/or call the base class
    m_pCustomView = new CustomView;
    m_pCustomView->Create(NULL,NULL,0L,CFrameWnd::rectDefault,this,VIEW_CUSTOM, pContext);
    SetActiveView(m_pCustomView);
    m_pCustomView->ShowWindow(SW_NORMAL);
    RecalcLayout();
    return true;
}

我不知道我做错了什么,但是CustomView没有加载到右侧窗格中。

有关更改方法的任何建议或当前方法有什么问题?

1 个答案:

答案 0 :(得分:0)

您必须将自定义视图直接放入分割窗口右侧,而不是CFrameWnd内。

if (!m_SplitterWnd.CreateView(0, 0, RUNTIME_CLASS(CLeftTreeView), CSize(125, 100), pContext) 
|| !m_SplitterWnd.CreateView(0, 1, RUNTIME_CLASS(CCustomView), CSize(100, 100), pContext))

{
    m_SplitterWnd.DestroyWindow();
    return FALSE;
}