Solved

Tool bar alignment

Posted on 2001-08-09
10
335 Views
Last Modified: 2013-11-20
In an Doc/View MFC application i have five toolbars .I want to align it one after another in an linear fashion below the Menu.I have created these toolbar as CBRS_ALIGN_ANY.I use the following logic

I have now five toolbar objects;

Now i call CMainFrame::PlaceControlBar() in the following order.

PlaceControlBar( NULL, &m_wndToolBar );
PlaceControlBar( &m_wndToolBar, &m_wndToolBar2 );
PlaceControlBar( &m_wndToolBar2,&m_wndMapTool);
PlaceControlBar( &m_wndMapTool, &m_wndDateBar );
PlaceControlBar( &m_wndDateBar, &m_wndViewScale);

void CMainFrame::PlaceControlBar( CControlBar* pLast, CControlBar* pCurrent )
{
     if( pLast == NULL )
     {
          DockControlBar(pCurrent, AFX_IDW_DOCKBAR_TOP, NULL );
          RecalcLayout();
          return;
     }

     ASSERT( pLast != NULL );
     ASSERT( pCurrent != NULL );

     CRect rcLast;
     
     // Toolbar placement forces non-client areas to overlap.
     // Hence we use the client rectangle and not the window rectangle.
     pLast->GetClientRect( &rcLast );
     pLast->ClientToScreen( &rcLast );
     
     CRect rcDock(rcLast.right, rcLast.top, rcLast.right+1, rcLast.top+1 );
     
     DockControlBar(pCurrent, AFX_IDW_DOCKBAR_TOP, &rcDock );

     RecalcLayout();
}

now comming to the problem.Only the first three toolbars are aligned one after another in one line,but the next two toolbar is taking the place of next row even though there is enough space in first row.How to solve this problem?
0
Comment
Question by:gymsam
10 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 6375264
DockControlBar expects screen coords, you are passing client coords.  This...

CRect rcPrev, rcCur;

pBarPrev->GetWindowRect( &rcPrev );
pBarCur->GetWindowRect( &rcCur );
rcCur= rcPrev;
rcCur.OffsetRect( rcPrev.Width(), 0 );
DockControlBar( pBarCur, AFX_IDW_DOCKBAR_TOP, rcCur);

...will work, right up until you try too add too many toolbars.  For instance, if no part of toolbar #5 will fit, then RecalcLayout() will force it to move down to the second line.

The only way to avoid that is to check rcPrev.right and if it is more than the Frame window's right side, then hide it.

Furthermore, if the user re-sizes the frame, it can cause the rightmost bar to move down to a lower line.  This is by design.  It is standard Windows UI and if you want to do something different, you are breaking User Interface rules and will confuse your users.  Also, you will need to do extra work (hide and show bars in your OnSize handler).

-- Dan
0
 

Author Comment

by:gymsam
ID: 6378818
I tried your option still its not aligning single row.3 tool bars in first row and rest two in next row.i think GetWindowRect will not give screen coordinates.Any other way?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6379041
It works.  That is functional, tested code.  It assumes that you have called Create for each bar and that you have called RecalcLayout() on the Frame after creating each bar and also called EnableDocking(CBRS_ALIGN_TOP) for each bar.

If there is room for any part of the third bar, it will appear in the top row.  If there is room for any part of the fourth bar, it will also appear on the top row.  Otherwise, there will be two rows of bars.

-- Dan
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:gymsam
ID: 6379367
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6420457
hi gymsam,
Do you have any additional questions?  Do any comments need clarification?

-- Dan
0
 

Author Comment

by:gymsam
ID: 6421119
I will get you little latter
0
 
LVL 7

Expert Comment

by:peterchen092700
ID: 6421438
Dan: yeah, he'll get all of us ;)

gymsam: just an idea - I just encountered a similar problem today, with a almost stupid solution: I had a dialog bar with the dialog resource in use much wider than necessary. guess what happened... the dialog bar was placed on a new row, although the controls itself would have fit....
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6423317
Yes, and the "wrapping" problem also goes away if you make one or two large toolbars instead of many small ones.

-- Dan
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 100 total points
ID: 6443880
hi gymsam,
Do you have any additional questions?  Do any comments need clarification?

-- Dan
0
 
LVL 1

Expert Comment

by:Computer101
ID: 6703240
Comment from DanRollins accepted as answer.

Thank you
Computer101
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question