怎么可能有用啊!你刚创建了它,然后在你调用的函数结束时又把它给杀掉了啊。把你的CToolBar m_toolbar变成类成员变量吧!

解决方案 »

  1.   

    对不是,我的程序中是(AfxGetMainWnd()) ,刚才输入有误!
      

  2.   

    milson(老疯子) :我试过了,也没用。
      

  3.   

    你调用如下代码在什么地方:m_toolbar.CreateEx(AfxGetMainWnd());
    m_toolbar.LoadToolBar(IDR_TOOLBAR1);
      

  4.   

    我把它放到CMainFrame::OnCreate()里,可以啊!
      

  5.   

    基于对话框程序中没有CMainFrame
      

  6.   

    查找
    toolbar
    已经悠源码!
      

  7.   

    还是铁出来吧
    在对话框中使用Toolbar(其实对所有CControlBar类的子类都是如此)比较麻烦,除了要创建之外,还得(得Create之后)进行如下工作:  ——直接把以下代码添到dlg 类的OnInitDialog中就OK了。1.用reposQuery得出ControlBar需要占用多少空间。
    CRect rcClientStart;
    CRect rcClientNow;
    GetClientRect(rcClientStart);
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST,
        AFX_IDW_CONTROLBAR_LAST,
        0, reposQuery, rcClientNow);2.挪动原有控件为ControlBar挪出空间
    // Now move all the controls so they are in the same relative
    // position within the remaining client area as they would be
    // with no control bars.
    CPoint ptOffset(rcClientNow.left - rcClientStart.left,
        rcClientNow.top - rcClientStart.top);CRect  rcChild;
    CWnd* pwndChild = GetWindow(GW_CHILD);
    while (pwndChild)
    {
        pwndChild->GetWindowRect(rcChild);
        ScreenToClient(rcChild);
        rcChild.OffsetRect(ptOffset);
        pwndChild->MoveWindow(rcChild, FALSE);
        pwndChild = pwndChild->GetNextWindow();
    }3.调整窗口大小
    // Adjust the dialog window dimensions
    CRect rcWindow;
    GetWindowRect(rcWindow);
    rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
    rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
    MoveWindow(rcWindow, FALSE);4.最后真正放置ControlBar
    // And position the control bars
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);