我想制作一个工具栏,有三部分组成
左侧是放置两个的工具栏,右侧放一个可以分页显示的工具栏
请问如何设置这三个工具栏的位置????

解决方案 »

  1.   

    做好了以后用DockControlBar就可以了,自己看MSDN好了
      

  2.   

    #if !defined(AFX_PALETTEBAR_H__1DA81D5B_E98A_4FAB_97DE_5F21428183FE__INCLUDED_)
    #define AFX_PALETTEBAR_H__1DA81D5B_E98A_4FAB_97DE_5F21428183FE__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    // PaletteBar.h : header file
    ///////////////////////////////////////////////////////////////////////////////
    // CPaletteBar window#ifndef INC_TOOLBAR2_H
    #define INC_TOOLBAR2_Hclass CPaletteBar : public CToolBarCtrl
    {
    private:
    int         m_nButtonCount;
    TBBUTTON    *m_pTBButtons;// Construction
    public:
    CPaletteBar();// Attributes
    public:// Operations
    public:
    // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CPaletteBar)
    public:
    virtual BOOL OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult);
    virtual BOOL Create( DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);
    //}}AFX_VIRTUAL
    // Implementation
    public:
    virtual ~CPaletteBar();protected:
    BOOL BeginAdjust(WPARAM wParam, LPARAM lParam, LRESULT* pLResult);
    BOOL BeginDrag(WPARAM wParam, LPARAM  lParam, LRESULT* pLResult);
    BOOL CustomizeHelp(WPARAM wParam, LPARAM  lParam, LRESULT* pLResult);
    BOOL EndAdjust(WPARAM wParam, LPARAM  lParam, LRESULT* pLResult);
    BOOL EndDrag(WPARAM wParam, LPARAM  lParam, LRESULT* pLResult);
    BOOL GetButtonInfo(WPARAM wParam, LPARAM  lParam, LRESULT* pLResult);
    BOOL QueryDelete(WPARAM wParam, LPARAM  lParam, LRESULT* pLResult);
    BOOL QueryInsert(WPARAM wParam, LPARAM  lParam, LRESULT* pLResult);
    BOOL Reset(WPARAM wParam, LPARAM lParam, LRESULT* pLResult);
    BOOL ToolBarChange(WPARAM wParam, LPARAM lParam,LRESULT* pLResult);
    CString NeedText(UINT nID, NMHDR * pNotifyStruct, LRESULT * lResult);///////////////////////////////////////////////////////////////////////////////
    // Following function has to be removed when OnNotify is fixed
    //
    virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult);
    //
    /////////////////////////////////////////////////////////////////////////////// // Generated message map functions
    protected:
    //{{AFX_MSG(CPaletteBar)
    afx_msg void OnNeedTextW( UINT nID, NMHDR * pNotifyStruct, LRESULT * lResult );
    afx_msg void OnNeedTextA( UINT nID, NMHDR * pNotifyStruct, LRESULT * lResult );


    //}}AFX_MSG DECLARE_MESSAGE_MAP()
    };#endif
    ///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_PALETTEBAR_H__1DA81D5B_E98A_4FAB_97DE_5F21428183FE__INCLUDED_)
    // PaletteBar.cpp : implementation file
    //#include "stdafx.h"
    #include "Graph.h"
    #include "PaletteBar.h"
    #include "afxpriv.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CPaletteBarCPaletteBar::CPaletteBar() : m_pTBButtons(NULL)
    {}CPaletteBar::~CPaletteBar()
    {
    if (m_pTBButtons)
    delete []m_pTBButtons;}
    BEGIN_MESSAGE_MAP(CPaletteBar, CToolBarCtrl)
    //{{AFX_MSG_MAP(CPaletteBar)
    ON_NOTIFY_RANGE( TTN_NEEDTEXTA, ID_DRAWSELECT, ID_DRAWTRIAN, OnNeedTextA)
    ON_NOTIFY_RANGE( TTN_NEEDTEXTW, ID_DRAWSELECT, ID_DRAWTRIAN, OnNeedTextW)

    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    BOOL CPaletteBar::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID )
    {
     BOOL bRet = CToolBarCtrl::Create(dwStyle, rect, pParentWnd, nID); m_nButtonCount =ID_DRAWTRIAN - ID_DRAWSELECT + 1; VERIFY(AddBitmap(m_nButtonCount,IDR_PALETTEBAR) != -1); m_pTBButtons = new TBBUTTON[m_nButtonCount]; for (int nIndex = 0; nIndex < m_nButtonCount; nIndex++)
    {
    CString string;
    string.LoadString(nIndex + ID_DRAWSELECT); // Add second '\0'
    int nStringLength = string.GetLength() + 1;
    TCHAR* pString = string.GetBufferSetLength(nStringLength);
    pString[nStringLength] = 0;
    pString[4]=0;
    VERIFY((m_pTBButtons[nIndex].iString = AddStrings(pString)) != -1); string.ReleaseBuffer();
    m_pTBButtons[nIndex].fsState = TBSTATE_ENABLED;
    m_pTBButtons[nIndex].fsStyle = TBSTYLE_CHECKGROUP;
    m_pTBButtons[nIndex].dwData = 0;
    m_pTBButtons[nIndex].iBitmap = nIndex;
    m_pTBButtons[nIndex].idCommand = nIndex + ID_DRAWSELECT; }
    for (nIndex = 0; nIndex < m_nButtonCount; nIndex++)
    {
    VERIFY(AddButtons(1,&m_pTBButtons[nIndex]));
    }
    return bRet;
    }
    /////////////////////////////////////////////////////////////////////////////
    // CPaletteBar message handlers// MFC routes the notifications sent to the parent of the control to
    // the control before the parent can process the notification.
    // The control object can handle the notification or ignore it.
    // If the notification is handled then return TRUE. Otherwise MFC
    // will route it to the parent of the control.BOOL CPaletteBar::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
    {
    if (message == WM_NOTIFY)
    {
    NMHDR *pNMHDR = (NMHDR *) lParam;
    switch (pNMHDR->code)
    {
    case TBN_BEGINADJUST :
    return BeginAdjust(wParam,  lParam,  pLResult); case TBN_BEGINDRAG:
    return BeginDrag(wParam,  lParam,  pLResult); case TBN_CUSTHELP:
    return CustomizeHelp(wParam,  lParam,  pLResult); case TBN_ENDADJUST:
    return EndAdjust(wParam,  lParam,  pLResult); case TBN_ENDDRAG:
    return EndDrag(wParam,  lParam,  pLResult); case TBN_GETBUTTONINFO:
    return GetButtonInfo(wParam,  lParam,  pLResult); case TBN_QUERYDELETE:
    return QueryDelete(wParam,  lParam,  pLResult); case TBN_QUERYINSERT:
    return QueryInsert(wParam,  lParam,  pLResult); case TBN_RESET:
    return Reset(wParam, lParam,  pLResult); case TBN_TOOLBARCHANGE:
    return ToolBarChange(wParam, lParam, pLResult);
    }
    } return CToolBarCtrl::OnChildNotify(message, wParam, lParam, pLResult);
    }BOOL CPaletteBar::BeginAdjust(WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
    {
    TRACE(_T("TBN_BEGINADJUST\n")); // the customize dialog box is about to be displayed // save toolbar state before customization using the dialog
    // Use this information to restore the state if reset button is pressed
    //SaveState(HKEY_CURRENT_USER,_T("Software\\Microsoft\\VC40\\Samples\\CtrlDemo"),_T("Palette Tool Bar")); return TRUE;
    }BOOL CPaletteBar::BeginDrag(WPARAM wParam, LPARAM  lParam, LRESULT* pLResult)
    {
    TRACE(_T("TBN_BEGINDRAG\n")); // we are not implementing custon drag and drop
    * pLResult = FALSE;
    return FALSE;
    }BOOL CPaletteBar::CustomizeHelp(WPARAM wParam, LPARAM  lParam, LRESULT* pLResult)
    {
    TRACE(_T("TBN_CUSTHELP\n")); // Sample displays a message box but a valid help topic
    // can be displayed for the customize dialog for this toolbar
    //AfxMessageBox(_T("Help not implemented!")); return TRUE;
    }BOOL CPaletteBar::EndAdjust(WPARAM wParam, LPARAM  lParam, LRESULT* pLResult)
    {
    TRACE(_T("TBN_ENDADJUST\n")); // the customize dialog box has been closed return TRUE;
    }BOOL CPaletteBar::EndDrag(WPARAM wParam, LPARAM  lParam, LRESULT* pLResult)
    {
    TRACE(_T("TBN_ENDDRAG\n")); // Code to handle custom drag and drop. This message indicates that
    // the item is being dropped
    * pLResult = FALSE;
    return TRUE;
    }
      

  3.   

    BOOL CPaletteBar::GetButtonInfo(WPARAM wParam, LPARAM  lParam, LRESULT* pLResult)
    {
    // This notification message has to be handled correctly if
    // all operations in the custom dialogbox has to function correctly
    // We have to supply information for the button specified by pTBN->tbButton
    //
    // This notification is sent in the following cases
    //
    // After TBN_BEGINADJUST the control sends these notifications until
    // * pLResult is TRUE. We have to supply valid values when this value is
    // set to TRUE. Here the control is collecting information for all
    // the buttons that have to be displayed in the dialog box
    //
    // The control sends this notification to get information about
    // a button if the user is trying to add it to the toolbar or
    // rearranging the buttons on the toolbar from within the dialog TRACE(_T("TBN_GETBUTTONINFO\n")); TBNOTIFY *pTBN = (TBNOTIFY *) lParam; if (pTBN->iItem >= m_nButtonCount)
    {
    * pLResult = FALSE;
    }
    else
    {
    CString buffer;
    buffer.LoadString(pTBN->iItem + ID_DRAWLINE);
    //buffer=buffer.Left(2);
    // set the string for the button
    // truncate the string if its length is greater than the buffer
    // supplied by the toolbar
    _tcsncpy(pTBN->pszText, buffer, pTBN->cchText - 2);
    pTBN->pszText[pTBN->cchText - 1] = '\0'; // set the button info
    pTBN->tbButton = m_pTBButtons[pTBN->iItem]; // valid values are structure
    *pLResult = TRUE;
    } return TRUE;
    }BOOL CPaletteBar::QueryDelete(WPARAM wParam, LPARAM  lParam, LRESULT* pLResult)
    {
    TRACE(_T("TBN_QUERYDELETE\n")); // in this sample any button can be deleted
    // if a particular button cannot be deleted set *pResult to FALSE for that item
    *pLResult = TRUE;
    return TRUE;
    }BOOL CPaletteBar::QueryInsert(WPARAM wParam, LPARAM  lParam, LRESULT* pLResult)
    {
    TRACE(_T("TBN_QUERYINSERT\n")); // in this sample buttons can be inserted at any location on the
    // toolbar
    *pLResult = TRUE;
    return TRUE;
    }BOOL CPaletteBar::Reset(WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
    {
    TRACE(_T("TBN_RESET\n")); // User has pressed the reset button
    // restore the state of the toolbar to the state it was before customization
    //RestoreState(HKEY_CURRENT_USER,_T("Software\\Microsoft\\VC40\\Samples\\CtrlDemo"),_T("Palette Tool Bar")); *pLResult = TRUE;
    return TRUE;
    }BOOL CPaletteBar::ToolBarChange(WPARAM wParam, LPARAM lParam,LRESULT* pLResult)
    {
    TRACE(_T("TBN_TOOLBARCHANGE\n")); // the toolbar has changed
    return TRUE;
    }
    // Helper function for tooltipsCString CPaletteBar::NeedText( UINT nID, NMHDR * pNotifyStruct, LRESULT * lResult )
    {
    LPTOOLTIPTEXT lpTTT = (LPTOOLTIPTEXT)pNotifyStruct ;
    ASSERT(nID == lpTTT->hdr.idFrom); CString toolTipText;
    toolTipText.LoadString(nID); // szText length is 80
    int nLength = (toolTipText.GetLength() > 79) ? 79 : toolTipText.GetLength(); toolTipText = toolTipText.Left(nLength); return toolTipText;
    }
    void CPaletteBar::OnNeedTextW( UINT nID, NMHDR * pNotifyStruct, LRESULT * lResult )
    {
    CString toolTipText = NeedText(nID, pNotifyStruct, lResult); LPTOOLTIPTEXTW lpTTT = (LPTOOLTIPTEXTW)pNotifyStruct;#ifdef _UNICODE
    _tcsncpy(lpTTT->szText,(LPCTSTR)toolTipText, toolTipText.GetLength() +1);
    //#else
    // mbstowcs(lpTTT->szText,(LPCTSTR)toolTipText, toolTipText.GetLength() + 1);
    #endif
    }void CPaletteBar::OnNeedTextA( UINT nID, NMHDR * pNotifyStruct, LRESULT * lResult )
    {
    CString toolTipText = NeedText(nID, pNotifyStruct, lResult); LPTOOLTIPTEXT lpTTT = (LPTOOLTIPTEXT)pNotifyStruct;
    _tcscpy(lpTTT->szText,(LPCTSTR)toolTipText);
    }
    ///////////////////////////////////////////////////////////////////////
    // This has been overridden so we can handle the tooltip TTN_NEEDTEXT//
    // notification message                                              //
    ///////////////////////////////////////////////////////////////////////BOOL CPaletteBar::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
    {
    ASSERT(pResult != NULL);
    NMHDR* pNMHDR = (NMHDR*)lParam;
    HWND hWndCtrl = pNMHDR->hwndFrom; // get the child ID from the window itself
    // UINT nID = _AfxGetDlgCtrlID(hWndCtrl); //////////////////////////////////////////////////////////////////
    // If TTN_NEEDTEXT we cannot get the ID from the tooltip window //
    ////////////////////////////////////////////////////////////////// int nCode = pNMHDR->code; //
    // if it is the following notification message
    // nID has to obtained from wParam
    // if (nCode == TTN_NEEDTEXTA || nCode == TTN_NEEDTEXTW)
    {
    UINT nID;   // = _AfxGetDlgCtrlID(hWndCtrl);
    nID = (UINT)wParam;
    ASSERT((UINT)pNMHDR->idFrom == (UINT)wParam);
    UNUSED(wParam);  // not used in release build
    ASSERT(hWndCtrl != NULL);
    ASSERT(::IsWindow(hWndCtrl)); if (AfxGetThreadState()->m_hLockoutNotifyWindow == m_hWnd)
    return TRUE;        // locked out - ignore control notification // reflect notification to child window control
    if (ReflectLastMsg(hWndCtrl, pResult))
    return TRUE;        // eaten by child AFX_NOTIFY notify;
    notify.pResult = pResult;
    notify.pNMHDR = pNMHDR;
    return OnCmdMsg(nID, MAKELONG(nCode, WM_NOTIFY), &notify, NULL);
    } return CToolBarCtrl::OnNotify(wParam, lParam, pResult);
    }
      

  4.   

    m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
    EnableDocking(CBRS_ALIGN_ANY);
    DockControlBar(&m_wndToolBar);
    这三个函数,用不同的参数.
    CBRS_ALIGN_TOP   Allows docking at the top of the client area. 
    CBRS_ALIGN_BOTTOM   Allows docking at the bottom of the client area. 
    CBRS_ALIGN_LEFT   Allows docking on the left side of the client area. 
    CBRS_ALIGN_RIGHT   Allows docking on the right side of the client area. 
    CBRS_ALIGN_ANY   Allows docking on any side of the client area.
      

  5.   

    使用这个函数:
    void CMainFrame::DockControlBarLeftOf(CToolBar *Bar, CToolBar *LeftOf)
    {
    CRect rect;
    DWORD dw;
    UINT n;

    // get MFC to adjust the dimensions of all docked ToolBars
    // so that GetWindowRect will be accurate
    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;

    // When we take the default parameters on rect, DockControlBar will dock
    // each Toolbar on a seperate line. By calculating a rectangle, we
    // are simulating a Toolbar being dragged to that location and docked.
    DockControlBar(Bar,n,&rect);
    }