我想编一个可浮动停靠工作空间,其中包含了树视控件。
在一本书上有相关的代码
首先是采用Appwizard exe建立一个多文档的应用程序,
然后通过资源编辑器中的Resource Symbols添加两个ID值IDC_WORKSPACE和IDC_TREECTRL.但这两个资源总是不在使用!
然后自写一个可浮动停靠工作空间类及其实现文件。
问题是,mainframe.cpp中申明这个类的一个实例:CMyCtrlBar m_wndWorkspace时总是报类没有实例化,
如果将这句注释掉就编译成功。

解决方案 »

  1.   

    CMyCtrlBar有没有默认的构造函数呢
      

  2.   

    有的。CMyCtrlBar.h文件如下:
    #if !defined(__MYCTRLBAR_H__)
    #define __MYCTRLBAR_H__#include "MyTreeCtrl.h"
    #include "Ex19Doc.h"#include <afxpriv.h>    // for CDockContext
    #include <afxtempl.h>   // for CArray#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    // MyCtrlBar.h : header file
    //
    /////////////////////////////////////////////////////////////////////////////
    // CMyCtrlBar window
    class CMyCtrlBar : public CControlBar
    {
    DECLARE_DYNAMIC(CMyCtrlBar)// Construction
    public:
    CMyCtrlBar();// Attributes
    protected:
    BOOL m_bInRecalcNC;
    BOOL m_bTracking;
    BOOL m_bGripper;
    UINT m_cxEdge;
    UINT m_nDockBarID;
    CSize m_sizeMin;
    CSize m_sizeHorz;
    CSize m_sizeVert;
    CSize m_sizeFloat;
    CRect m_rectBorder;
    CRect m_rectTracker;
    CPoint m_ptOld;
    DWORD dwStyle;
    // Operations
    public:
    virtual void OnUpDateCmdUI(CFrameWnd* pTarget,
    BOOL bDisableIfNoHndler);
    virtual BOOL Create(CWnd* pParentWnd,UINT nID,
    LPCTSTR lpszWindowName=NULL,
    CSize sizeDefault=CSize(200,200),
    DWORD dwStyle=WS_CHILD|WS_VISIBLE|CBRS_TOP);
    virtual CSize CalcFixedLayout(BOOL bStretch,BOOL bHorz);
    virtual CSize CalcDynamicLayout(int nLength,DWORD dwMode);// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CMyCtrlBar)
    //}}AFX_VIRTUAL// Implementation
    public:
    void ReDrawTree(CEx19Doc *pDoc);
    TVITEM tvitem;
    CMyTreeCtrl*  treectrl;
    BOOL IsHorzDocked() const;
    BOOL IsVertDocked() const;
    BOOL IsFloating(); void OnInvertTracker(const CRect& rect);
    void StopTracking(BOOL bAccept);
    void StartTracking();
    CPoint& ClientToWnd(CPoint& point);
    virtual ~CMyCtrlBar(); // Generated message map functions
    protected:
    //{{AFX_MSG(CMyCtrlBar)
    afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
    afx_msg void OnMouseMove(UINT nFlags, CPoint point);
    afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
    afx_msg void OnWindowPosChanged(WINDOWPOS FAR* lpwndpos);
    afx_msg void OnNcLButtonDown(UINT nHitTest, CPoint point);
    afx_msg void OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp);
    afx_msg void OnNcPaint();
    afx_msg UINT OnNcHitTest(CPoint point);
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    afx_msg void OnCaptureChanged(CWnd *pWnd);
    afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
    afx_msg void OnPaint();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };
    ///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(__MYCTRLBAR_H__)