Solved

Tool bar alignment

Posted on 2001-08-09
10
325 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
 

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now