GSI

2개의 툴바를 한줄에

C++ 2007. 10. 27. 02:19 |

class CMainFrame : public CFrame
{
protected:
    CToolBar wnd_myToolBar;
    CToolBar wnd_othToolBar;
    ...
};

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    ...
    wnd_myToolBar.Create(...);
    wnd_othToolBar.Create(...);
    ...
}

DockControlBarLeftOf 함수를 이용하면 가능합니다. DockControlBarLeftOf(CToolBar* Bar, CToolBar* LeftOf)처럼 두 개의 툴바를 인수로 받기 때문입니다. 따라서 Bar와 LeftOf 툴바는 한줄에 출력될 것입니다. 다음 코드를 참고하기 바랍니다.

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    ...
    EnableDocking(CBRS_ALIGN_ANY);

    m_wndToolBar.SetWindowText(_T("myToolBar"));
    m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
    DockControlBar(&m_wndToolBar, AFX_IDW_DOCKBAR_TOP);

    wnd_othToolBar.SetWindowText(_T("otherToolBar"));
    wnd_othToolBar.EnableDocking(CBRS_ALIGN_ANY);
    DockControlBarLeftOf(&m_wndToolBar, &wnd_othToolBar);
   ...
}

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();
    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 in effect
    // are simulating a Toolbar being dragged to that location and docked.
    DockControlBar(Bar,n,&rect);
}

Posted by gsi
: