Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Tool bar alignment

Posted on 2001-08-09
10
Medium Priority
?
350 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 400 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

730 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