Solved

Tool bar alignment

Posted on 2001-08-09
10
341 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
Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

 

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

Webinar: MongoDB® Index Types

Join Percona’s Senior Technical Services Engineer, Adamo Tonete as he presents “MongoDB Index Types, How, When and Where Should They be Used?” on Wednesday, July 12, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7).

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

632 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