Link to home
Start Free TrialLog in
Avatar of okg
okg

asked on

How to dock mutiple toolbars in a row ?

Dear experts
I'm using VC++5.0 in WindowsNT4.0.
I'd like to dock mutiple toolbars in a row, i.e. top row.
I tried as following codes.
Where I created 4 toolbars.
As you see, my app has three mode(user interface is changed in each mode), and each mode has its toolbar. So the other toolbars are hided.
But one of four toolbars, m_wndCommonToolbar, is displayed in every mode.
Anyway, problem is they (i.e. anyone of mode toolbar and m_wndCommonToolbar) aren't docked in a row.
At start up, they(e.g. DesignToolbar and Common toolbar) has its own row. i.e. So, totally two rows.
Even I dragged they into a row, if I changed mode and come back, they (including status bar) are scattered again.
Any comments will be appreciated.
---- source code ------
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
      CWnd wnd;

      WINDOWPLACEMENT windowInfo;
      windowInfo.length = sizeof( WINDOWPLACEMENT );
      windowInfo.showCmd = SW_HIDE;

      if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
            return -1;
      SetWindowPos( &wnd, 0, 0, 1024, 768, 0 );

      m_wndDesignToolBar.CreateToolBar(this, IDR_MAINFRAME ); // CBRS_SIZE_DYNAMIC flag is set.

      m_wndDesignToolBar.SetBarStyle(m_wndDesignToolBar.GetBarStyle() |
            CBRS_TOOLTIPS | CBRS_FLYBY );

      if (!m_wndPlayToolBar.Create(this) ||
            !m_wndPlayToolBar.LoadToolBar(IDR_TRANSMITMENU))
      {
            TRACE0("Failed to create toolbar\n");
            return -1;      // fail to create
      }

      m_wndPlayToolBar.SetBarStyle(m_wndPlayToolBar.GetBarStyle() |
            CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_FIXED);

      if (!m_wndMotionToolBar.Create(this) ||
            !m_wndMotionToolBar.LoadToolBar(IDR_MOTION_MENU))
      {
            TRACE0("Failed to create toolbar\n");
            return -1;      // fail to create
      }

      m_wndMotionToolBar.SetBarStyle(m_wndMotionToolBar.GetBarStyle() |
            CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_FIXED);

      if(!m_wndCommonToolBar.Create(this) ||
            !m_wndCommonToolBar.LoadToolBar(IDR_COMMON_TOOLBAR))
      {
            TRACE0("Failed to create Common toolbar\n");
            return -1;      // fail to create
      }

      m_wndCommonToolBar.SetBarStyle(m_wndCommonToolBar.GetBarStyle() |
            CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_FIXED);

      m_wndDesignToolBar.EnableDocking(CBRS_ALIGN_TOP);
      m_wndPlayToolBar.EnableDocking(CBRS_ALIGN_TOP);
      m_wndMotionToolBar.EnableDocking(CBRS_ALIGN_TOP);
      m_wndCommonToolBar.EnableDocking(CBRS_ALIGN_TOP);
      EnableDocking(CBRS_ALIGN_TOP);

      RecalcLayout();

      CRect rtWnd;

      m_wndDesignToolBar.GetWindowRect(rtWnd);
      rtWnd.OffsetRect(0, -72);
      DockControlBar(&m_wndDesignToolBar, AFX_IDW_DOCKBAR_TOP, rtWnd);
      RecalcLayout();

      m_wndCommonToolBar.GetWindowRect(rtWnd); // having 3 buttons
      rtWnd.OffsetRect(950, 0);
      DockControlBar(&m_wndCommonToolBar, AFX_IDW_DOCKBAR_TOP, rtWnd);
      RecalcLayout();


      m_wndPlayToolBar.GetWindowRect(rtWnd);
      // rtWnd.OffsetRect(0, 0);
      DockControlBar(&m_wndPlayToolBar, AFX_IDW_DOCKBAR_TOP, rtWnd);
      RecalcLayout();

      m_wndMotionToolBar.GetWindowRect(rtWnd);
      // rtWnd.OffsetRect(0, 0);
      DockControlBar(&m_wndMotionToolBar, AFX_IDW_DOCKBAR_TOP, rtWnd);
      RecalcLayout();

      ShowControlBar(&m_wndCommonToolBar, TRUE, FALSE);
      ShowControlBar(&m_wndDesignToolBar, TRUE, FALSE);
      ShowControlBar(&m_wndMotionToolBar, FALSE, FALSE);
      ShowControlBar(&m_wndPlayToolBar, FALSE, FALSE);

      //
      if (!m_wndStatusBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM, ID_CG_STATUS_BAR ) ||
            !m_wndStatusBar.SetIndicators(indicators,
              sizeof(indicators) / sizeof(UINT)) )
      {
            TRACE0("Failed to create status bar\n");
            return -1;      // fail to create
      }

      //
      SetCursor( LoadCursor( NULL, IDC_ARROW ) );

      return 0;
}

ASKER CERTIFIED SOLUTION
Avatar of naveenkohli
naveenkohli

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial