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


Multiple toolbars

Posted on 1999-07-30
Medium Priority
Last Modified: 2013-11-20
I've got a moderatly customized MFC application.  currently a toolbar is loaded with each doc-template (1 at a time).  Now I want to add another toolbar to be visible with all templates.  The default dock location for the second bar should be top and right.  

I've created a CToolBar member in my frame class just like the original and mimick the code to create, set style  and enable.  But when I load it, strange and varied things happen.

What exact steps are needed to add a second docking toolbar.  What have I missed?
Question by:slewis112097
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
  • 2
  • 2

Author Comment

ID: 1312125
Edited text of question.
LVL 23

Accepted Solution

naveenkohli earned 150 total points
ID: 1312126
Look at the folowinf code .. it adds three toolbars and a dialog bar ...

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
      if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
            return -1;
      // Center the frame window.

      CenterWindow ();

      if (!m_wndToolBar.Create(this) ||
            TRACE0("Failed to create toolbar\n");
            return -1;      // fail to create

      m_wndToolBar.AddDropdownArrow (ID_FILE_OPEN);

      // Create the ToolBar for shapes.

      if (!m_wndShapeToolBar.Create(this,
            TRACE0("Failed to create toolbar\n");
            return -1;      // fail to create

      // Set the caption for the floating tool bar.

      m_wndShapeToolBar.SetWindowText (_T ("Shapes"));

      // Create tool bar for browser.

      if (!m_wndWebToolBar.Create(this,
            TRACE0("Failed to create toolbar\n");
            return -1;      // fail to create

      // Set the caption for the floating tool bar.

      m_wndWebToolBar.SetWindowText (_T ("Browser"));

      if (!m_wndStatusBar.Create(this) ||
            TRACE0("Failed to create status bar\n");
            return -1;      // fail to create

      // Create the dialogbar control.

      if (!m_wndDlgBar.Create (this, IDD_MY_DIALOGBAR, CBRS_TOP, ID_MY_DIALOGBAR)) {
            TRACE (_T ("Failed to create dialog bor!\n"));
            return -1;

      // Set the caption for the floating dialog bar.

      m_wndDlgBar.SetWindowText (_T ("Dialog bar"));

      // TODO: Remove this if you don't want tool tips or a resizeable toolbar

      m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |

      m_wndShapeToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |

      m_wndWebToolBar.SetBarStyle(m_wndWebToolBar.GetBarStyle() |

      m_wndDlgBar.SetBarStyle (m_wndDlgBar.GetBarStyle () |

      // TODO: Delete these three lines if you don't want the toolbar to
      //  be dockable
      m_wndDlgBar.EnableDocking (CBRS_ALIGN_ANY);


      DockControlBar(&m_wndShapeToolBar, AFX_IDW_DOCKBAR_LEFT);
      DockBarNextTo (&m_wndDlgBar, &m_wndToolBar);
//      DockControlBar(&m_wndDlgBar, AFX_IDW_DOCKBAR_LEFT);

      CToolBarCtrl *pToolBarCtrl = NULL;
      pToolBarCtrl = &m_wndShapeToolBar.GetToolBarCtrl ();
      TBBUTTON tbButton;
      pToolBarCtrl->GetButton (0, &tbButton);

      ShowControlBar (&m_wndShapeToolBar, FALSE, FALSE);
//      DockControlBar(&m_wndWebToolBar, AFX_IDW_DOCKBAR_RIGHT);

      // Load the toolbar states.
      LoadBarState (strBarState);
      return 0;

Author Comment

ID: 1312127
Sir, that is pretty much were I was already at, the problem is the arrangement of the bars.  I want the original bar in it's original place for a default(as I save the settings).  But I want the new toolbar to default to being on the same "y" axis and docked to the right.  I don't care what a user does with it after that, I'll put it back.

So that is really the heart of my question, which I realize now was not clear.
LVL 23

Expert Comment

ID: 1312128
1.To save the position of toolbars when user exits, call SaveBarState function on frame.

void CMainFrame::OnClose()
      SaveBarState (strBarState);

2. And when the aplication starts, you will call the LoadBarState function at the end of OnCreate function..

3. And to position the toolbars next to any toolbar, have a function like this where you can speify the toolbar to place the new bar next to.

void CMainFrame::DockBarNextTo (CControlBar *pBarToDock, CControlBar *pDockedBar,
                                             UINT nDockBarID)
      ASSERT_VALID (pBarToDock);
      ASSERT_VALID (pDockedBar);

      // Get the pointer to frame of docked bar.

      CFrameWnd *pFrameWnd = pDockedBar->GetDockingFrame ();
      ASSERT_VALID (pFrameWnd);

      // Force reclauclation of positions on frame.

      pFrameWnd->RecalcLayout ();

      // Get the position of docked bar.

      CRect rect;
      pDockedBar->GetWindowRect (&rect);

      // Offset the rectangle to bottom right so that the new bar we want to dock
      // goes either to the right or bottom of the already docked bar. The (right or
      // botom side depends on the side where this last bar is already docked. e.g.
      // If the docked bar is on side then new bar goes to bottom of it).

      rect.OffsetRect (1, 1);

      // Now dock the new bar.

      pFrameWnd->DockControlBar (pBarToDock, nDockBarID, &rect);

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : All lightning effects with instructions : http://www.mediaf…

715 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