Dock two toolbars side-by-side
Casey E Mullen -- mullenc@battelle.org
Wednesday, August 14, 1996
Environment: VC++ 4.0 Windows 95
I can use CFrameWnd::DockControlBar with AFX_IDW_DOCKBAR_TOP to dock
my toolbar at the top, but when I have more than one, they stack up
vertically rather than side-by-side, wasting a lot of valuable real
estate.
Has anyone already dealt with the issue of making two toolbars dock
side-by-side at the top of the screen?
Thanks,
Casey Mullen
Roy G. Browning -- ctf@sccsi.com
Thursday, August 15, 1996
[Mini-digest: 8 responses]
At 06:22 PM 8/14/96 -0500, you wrote:
> Environment: VC++ 4.0 Windows 95
> I can use CFrameWnd::DockControlBar with AFX_IDW_DOCKBAR_TOP to dock
> my toolbar at the top, but when I have more than one, they stack up
> vertically rather than side-by-side, wasting a lot of valuable real
> estate.
> Has anyone already dealt with the issue of making two toolbars dock
> side-by-side at the top of the screen?
> Casey Mullen
Casey;
The code below was taken directly from the "DOCKTOOL" example supplied with
Visual C++.
It works for me,
Roy Browning
////////////////////////////////////////////////////////////////////////////////
void
CMainFrame::DockControlBarLeftOf( CToolBar * barToDock, CToolBar * leftOf )
{
UINT n;
// get MFC to adjust the dimensions of all docked ToolBars
// so that GetWindowRect will be accurate
RecalcLayout();
CRect rect;
leftOf->GetWindowRect( &rect );
rect.OffsetRect( 1,0 );
DWORD dw = leftOf->GetBarStyle();
n = ( dw & CBRS_ALIGN_TOP ) ? AFX_IDW_DOCKBAR_TOP :
( dw & CBRS_ALIGN_BOTTOM ) ? AFX_IDW_DOCKBAR_BOTTOM :
( dw & CBRS_ALIGN_LEFT ) ? AFX_IDW_DOCKBAR_LEFT :
( dw & CBRS_ALIGN_RIGHT ) ? AFX_IDW_DOCKBAR_RIGHT : 0;
// When we take the default parameters on rect, DockControlBar will dock
// each Toolbar on a seperate line. y calculating a rectangle, we in effect
// are simulating a Toolbar being dragged to that location and docked.
DockControlBar( barToDock, n, &rect );
}
////////////////////////////////////////
C o n t r o l l i n g the F u t u r e
Software Design & Development
www.CtF.net
800-CTF-0032
Roy Browning - ctf@msn.com
///////////////////////////////////////
-----From: Don.Irvine@net-tel.co.uk
Look at the DOCKTOOL sample. Specically the function DockControlBarLeftOf in
mainfrm.cpp.
Don
-----From: "Cunningham Graham, IK 23"
I use the following code however I am also using Mark Conways dockable
window dll so it could be different but taking a quick look at the docs
and it should be ok.
//want to dock the cust list and the search bar side by side
CRect rcList, rcDlg;
m_wndSearchBar.GetWindowRect(&rcDlg);
m_CustomerListBar.GetWindowRect(&rcList);
rcDlg.BottomRight() = rcDlg.TopLeft() + rcList.Size();
DockControlBar(&m_wndSearchBar);
DockControlBar(&m_CustomerListBar, AFX_IDW_DOCKBAR_TOP, &rcDlg);
Graham Cunningham
00 41 31 338 0633
-----From: "Manolis Chr.Papadopoulos"
It was discussed here some time ago. Refer to DOCKTOOL example in the VC =
CD.
As stated in a former message, there are some problems which are focused =
on the LoadBarState() function. Just read the source code thoroughly and =
you will find everything you need.
Former messages can be found in ftp://advn.com/pub/mfc. You can search =
there two.
Manolis Papadopoulos
-----From: Jim Leavitt
Check out the docktool sample on your vc++ cd, everything you're
looking for is there.
Jim Leavitt
-----From: Mark Anderson
There is an example in DOCKTOOL sample app, but I'll include the code
here for fun :)
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);
}
And I call it in OnCreate like this
// This sets up the toolbar to be dockable
m_wndFileToolBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndViewToolBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndDesignToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndFileToolBar, AFX_IDW_DOCKBAR_TOP);
DockControlBarLeftOf(&m_wndViewToolBar, &m_wndFileToolBar);
DockControlBarLeftOf(&m_wndDesignToolBar, &m_wndViewToolBar);
I think I may rename this DockControlBarRightOf, because it docks with
the supplied supplementary toolbar (previously created) on the left of
the new toolbar, so your new toolbar is right of the old toolbar :)
Mark Anderson
fizban@bart.et.byu.edu 378-4538 CTB 75H
May the Force be with you. -- Obi Wan Kenobi
-----From: "Frank Clark"
The following should get it done.... I believe this (or some form of it)
originally came from
one of the samples which ship with VC++.
Frank_Clark@msn.com
In OnCreate:
// Allow docking on any side of main window
EnableDocking(CBRS_ALIGN_ANY);
// Dock Bars to default positions
DockControlBar(&m_wndToolBar, AFX_IDW_DOCKBAR_TOP);
DockControlBarLeftOf(&m_wndAsmToolBar, &m_wndToolBar);
#ifdef TPFSYS
DockControlBarLeftOf(&m_wndDebugBar, &m_wndAsmToolBar);
#endif
// Load user preferences for all Control Bars
LoadBarState(_T("General"));
---------------------------
void CMainFrame::DockControlBarLeftOf(CControlBar* Bar,CControlBar* 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);
}
-----From: John Lundy
Casey,
I have had to deal with this very issue before. The only way I could
get the toolbars placed like I wanted them was to override RecalcLayout in
my frame window. Here is a code snippet that shows what I did.
void CMainFrame::RecalcLayout(BOOL bNotify)
{
// Call the default function first!
CFrameWnd::RecalcLayout(bNotify);
// m_wndToolBar[] is an array of toolbar handles
// m_ToolRect[] is an array of rectangles where the toolbars "should" be
for (i=0 ; i < NumberOfToolbars ; i++)
{
m_wndToolBar[i].MoveWindow(&m_ToolRect, bNotify);
}
}
Hope this will help you out.
John Lundy
====================================================
John Lundy, Windows (16/32 bit) Software Developer
At Home Entertainment
Specializing in GUI, Multimedia and Game Development
====================================================
| Вернуться в корень Архива
|