【问题标题】:CSplitterWnd with two panes : left pane is CTreeView, Right is CFrameWnd : Not able to set different views in Right paneCSplitterWnd 有两个窗格:左窗格是 CTreeView,右是 CFrameWnd:无法在右窗格中设置不同的视图
【发布时间】:2013-10-12 06:20:40
【问题描述】:

我正在尝试实现经典的 Windows Explorer 类型的应用程序, CpliterWnd 有两个窗格:左窗格是 CLeftTreeView:公共 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 没有加载到右窗格中。

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

【问题讨论】:

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


    【解决方案1】:

    您必须将自定义视图直接放入拆分器窗口右侧,而不是 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;
    }
    

    【讨论】:

    • 感谢 dwo,抱歉回复延迟。
    猜你喜欢
    • 1970-01-01
    • 2018-02-11
    • 2015-07-27
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 2017-05-17
    • 1970-01-01
    相关资源
    最近更新 更多