开发者

finding some errors in making a toolbar using MFC

i added this in my header file

CToolBar myBar;
public:
int OnCreate(LPCREATESTRUCT lpCreateStruct);
void OnToolBarButton1();
void OnToolBarButton2();

and i added this in .cpp file

BEGIN_MESSAGE_MAP(CtoolbarfDlg, CDialog)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_WM_CREATE()
    ON_COMMAND(IDC_TBBU开发者_StackOverflow社区TTON1,OnToolBarButton1)
    ON_COMMAND(IDC_TBBUTTON2,OnToolBarButton2)  
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CtoolbarfDlg::OnToolBarButton1()
   {

   }
   void CtoolbarfDlg::OnToolBarButton2()
   {

   }

 int CtoolbarfDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
   {
       if (CDialog::OnCreate(lpCreateStruct) == -1)
           return -1;

       if (!myBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
          | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC))
      {
            TRACE0("Failed to create toolbar");
            return -1; // fail to create
      }

     myBar.LoadToolBar(IDR_TOOLBAR1);
     myBar.EnableDocking(CBRS_ALIGN_ANY);
     EnableDocking(CBRS_ALIGN_ANY);
     DockControlBar(&myBar);
   }

i got these errors :( error C3861: 'EnableDocking': identifier not found error C3861: 'DockControlBar': identifier not found


Based on BEGIN_MESSAGE_MAP(CtoolbarfDlg, CDialog), your CtoolbarfDlg class inherits from CDialog, not from CToolBar. Since EnableDocking() and DockControlBar() are methods of the CToolBar class, there is no definition for them in your class, which is why you see this error.

If your class does indeed inherits from CToolBar (you did not post the complete class declaration from your .h file, so I cannot know for sure), then BEGIN_MESSAGE_MAP should reflect that by being BEGIN_MESSAGE_MAP(CtoolbarfDlg, CToolBar).

Just to make sure I'm clear, the problematic lines in your code are

EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&myBar);

not

myBar.LoadToolBar(IDR_TOOLBAR1);
myBar.EnableDocking(CBRS_ALIGN_ANY);

which are fine because myBar is a CToolBar instance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜