【问题标题】:MFC CView into CDockablePaneMFC CView 进入 CDockablePane
【发布时间】:2014-12-06 11:41:30
【问题描述】:

我需要将 CView 派生类放入 CDockablePane。是否有任何代码示例,或者有人可以提供这样的代码吗?

我尝试了什么:

显然应该很简单,我在网上找到了类似“只需创建视图并将其父级设置为对话框或可停靠窗格或您想要的窗口类型”的建议。但是由于某种原因它不起作用,也许是因为它需要一个 CFrameWnd,我不知道。

无论如何,我需要能够在不创建另一个文档模板类的情况下做到这一点。只是为了使用预先存在的文档和视图类。

【问题讨论】:

    标签: c++ visual-c++ mfc docking document-view


    【解决方案1】:

    这是一个例子:

    从 CDockablePane 派生的类:

    //CRichEditPane .h

    class CRichEditPane : public CDockablePane
    {
        DECLARE_DYNAMIC(CRichEditPane)
    
    public:
        CRichEditPane();
        virtual ~CRichEditPane();
    
    protected:
        void AdjustLayout();
    protected:
        DECLARE_MESSAGE_MAP()
    public:
        afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
        afx_msg void OnSize(UINT nType, int cx, int cy);
    };
    

    //CRichEditPane .cpp

    IMPLEMENT_DYNAMIC(CRichEditPane, CDockablePane)
    
    CRichEditPane::CRichEditPane()
    {
    
    }
    
    CRichEditPane::~CRichEditPane()
    {
    }
    
    
    BEGIN_MESSAGE_MAP(CRichEditPane, CDockablePane)
        ON_WM_CREATE()
        ON_WM_SIZE()
    END_MESSAGE_MAP()
    
    
    // CRichEditPane message handlers
    
    
    int CRichEditPane::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
        if (CDockablePane::OnCreate(lpCreateStruct) == -1)
            return -1;
    
        CRuntimeClass *pClass = RUNTIME_CLASS(CRichEditViewInPane);
    
        // calling constructor using IMPLEMENT_DYNCREATE macro
        CRichEditViewInPane *pView = (CRichEditViewInPane*)pClass->CreateObject();
    
    
        if (!pView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, CRect(0,0,0,0), this, AFX_IDW_PANE_FIRST, NULL))
        {
            return -1;
        }
    
        CRichEditCtrl ctrl;
        ctrl.Create(WS_CHILD, CRect(0, 0, 0, 0), this, 10991);
    
        return 0;
    }
    
    
    void CRichEditPane::OnSize(UINT nType, int cx, int cy)
    {
        CDockablePane::OnSize(nType, cx, cy);
    
        AdjustLayout();
    }
    

    从 CView 派生的视图类:

    //CRichEditViewInPane .h

    class CRichEditViewInPane : public CRichEditView
    {
        DECLARE_DYNCREATE(CRichEditViewInPane)
    
    protected:
        CRichEditViewInPane();           // protected constructor used by dynamic creation
        virtual ~CRichEditViewInPane();
    
    public:
    #ifdef _DEBUG
        virtual void AssertValid() const;
    #ifndef _WIN32_WCE
        virtual void Dump(CDumpContext& dc) const;
    #endif
    #endif
    
    protected:
        DECLARE_MESSAGE_MAP()
    };
    

    //CRichEditViewInPane. cpp

    IMPLEMENT_DYNCREATE(CRichEditViewInPane, CRichEditView)
    
    CRichEditViewInPane::CRichEditViewInPane()
    {
    
    }
    
    CRichEditViewInPane::~CRichEditViewInPane()
    {
    }
    
    BEGIN_MESSAGE_MAP(CRichEditViewInPane, CRichEditView)
    END_MESSAGE_MAP()
    

    【讨论】:

    • 如何将其更改为 FormView?我无法访问 Create 函数,只能访问 CreateEx
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-16
    • 2012-12-18
    • 2010-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多