我现在有几个toolbar 要放到2行上面,每行上有几个,请问怎么做?有没有代码可以借鉴!

解决方案 »

  1.   

    CRebar rb;
    rb.add(Your toolbar);
      

  2.   

    有一个偷懒法,就是在Frame的OnCreate最低下加LoadBarState("起个名字"),在OnClose中加SaveBarState();然后运行一次,将位置排好,关软件,以后启动就好了.要研究原理,去研究它的函数内容吧,到现在还没弄懂.
      

  3.   

    我是在用vc做这个东西,我用了上面的CReBar,但是好像是有问题,那位能否再详细说说怎么样来用这个东西。谢谢了。
      

  4.   

    可以用ctoolbar解决的
    但是比较麻烦
    需要的话,给你个例子
      

  5.   

    直接用CToolbar就行了,它的停靠功能已经可以满足你的要求了!
      

  6.   

    给你一个很好用的函数://Global function used for docking any toolbar at anywhere!
    //The  nDocBarID can be anyone of the following style:
    //-----------------------------------------------------
    //AFX_IDW_DOCKBAR_TOP   Dock to the top side of the frame window.
    //AFX_IDW_DOCKBAR_BOTTOM   Dock to the bottom side of the frame window.
    //AFX_IDW_DOCKBAR_LEFT   Dock to the left side of the frame window.
    //AFX_IDW_DOCKBAR_RIGHT   Dock to the right side of the frame window.
    //If 0, the control bar can be docked to any side enabled for docking in the destination 
    //frame window.
    //-------------------------------------------------------void DockToolBarToSomewhere(CControlBar *pNewBar,CControlBar *pDockedBar,UINT nDockBarID=AFX_IDW_DOCKBAR_TOP)
    {
    ASSERT(pDockedBar!=NULL);
    ASSERT(pNewBar!=NULL); //Find the frame be docked!
    CFrameWnd *pFrame=pDockedBar->GetDockingFrame();
    ASSERT(pFrame!=NULL); //Calculate the pos of the docked toolbar
    pFrame->RecalcLayout();//must call the frame's function to calculate the size of  noclient
    CRect rect;
    pDockedBar->GetWindowRect(rect); //shift the "rect" to proper pos for docking at the right or bottom
    //because of the noclient has been changed,so update it!
    rect.OffsetRect(1,0);
    //docking to the good postion
    pFrame->DockControlBar(pNewBar,nDockBarID,&rect);
    }demo codes:
    ------------------------------
    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
    return -1;

    if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
    | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
    !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
    {
    TRACE0("Failed to create toolbar\n");
    return -1;      // fail to create
    } if (!m_wndNewToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
    | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
    !m_wndNewToolBar.LoadToolBar(IDR_TOOLBAR1))
    {
    TRACE0("Failed to create toolbar\n");
    return -1;      // fail to create
    } if (!m_wndStatusBar.Create(this) ||
    !m_wndStatusBar.SetIndicators(indicators,
      sizeof(indicators)/sizeof(UINT)))
    {
    TRACE0("Failed to create status bar\n");
    return -1;      // fail to create
    }

    EnableDocking(CBRS_ALIGN_ANY);// importance!!!must firstly call the frame's docking function!

    m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
    DockControlBar(&m_wndToolBar,AFX_IDW_DOCKBAR_TOP); m_wndNewToolBar.EnableDocking(CBRS_ALIGN_ANY);
    ::DockToolBarToSomewhere(&m_wndNewToolBar,&m_wndToolBar,AFX_IDW_DOCKBAR_TOP);

    return 0;
    }
    -----------------------------------------
    另一种方法是将辅助函数直接做成CMainFrame的一个成员函数,这样更符合面向对象的要求,
    但是减少了函数的通用性//使一个ControlBar停靠在另一个ControlBar 的旁边,而不是另起一行
    void CMainFrame::DockControlBarLeftOf(CControlBar *Bar, CControlBar *LeftOf)
    {
    CRect rect;
    DWORD dw;
    UINT n;
    //计算WindowRect的精确大小
    RecalcLayout();
    LeftOf ->GetWindowRect(&rect);
    rect.OffsetRect(1,0);
    dw = LeftOf ->GetBarStyle();
    n = 0;
    n = (dw & CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n;
    n = (dw & CBRS_ALIGN_BOTTOM && n == 0) ? AFX_IDW_DOCKBAR_BOTTOM : n;
    n = (dw & CBRS_ALIGN_LEFT && n == 0) ? AFX_IDW_DOCKBAR_LEFT : n;
    n = (dw & CBRS_ALIGN_RIGHT && n == 0) ? AFX_IDW_DOCKBAR_RIGHT : n; DockControlBar(Bar, n, &rect);
    }//===============================
    just run&enjoy it!南京
    宋业文
    [email protected]
    .....最好加分!嘿嘿!!。
      

  7.   

    我把void DockToolBarToSoemWhere放在mianfram.h的protected中,但是编译的时候有这个错误。
    'DockToolBarToSomewhere' : is not a member of '`global namespace''
      

  8.   

    void CMainFrame::DockControlBarLeftOf(CToolBar* Bar, CToolBar* LeftOf)
    {
    CRect rect;
    DWORD dw;
    UINT n;
    RecalcLayout(TRUE);
    LeftOf->GetWindowRect(&rect);
    rect.OffsetRect(1,0);
    dw=LeftOf->GetBarStyle();
    n = 0;
    n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n;
    n = (dw&CBRS_ALIGN_BOTTOM && n==0) ? AFX_IDW_DOCKBAR_BOTTOM : n;
    n = (dw&CBRS_ALIGN_LEFT && n==0) ? AFX_IDW_DOCKBAR_LEFT : n;
    n = (dw&CBRS_ALIGN_RIGHT && n==0) ? AFX_IDW_DOCKBAR_RIGHT : n;
    DockControlBar(Bar,n,&rect);
    }