Category Archives: Microsoft Foundation Classes

How to bring toolbars in a row using MFC (Microsoft Foundation Classes)

Normally you add Toolbars like this:

header file (‘MainFrm.h’):
………….
CMFCMenuBar m_wndMenuBar;
CMFCToolBar m_wndToolBar;
CMFCToolBar m_wndToolBar_Views3D;
CMFCToolBar m_wndToolBar_Export2D;
CMFCToolBar m_wndToolBar_Export3D;
………….

source file (‘MainFrm.cpp’):
………….
m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar_Views3D.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar_Export2D.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar_Export3D.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_wndMenuBar);
DockPane(&m_wndToolBar);
DockPane(&m_wndToolBar_Views3D);
DockPane(&m_wndToolBar_Export2D);
DockPane(&m_wndToolBar_Export3D);
………….

But this results in showing every toolbar on a new row …. 🙁

<img class="size-medium wp-image-30" src="https://i1.wp.com/home.varlab.eu/wp-content/uploads/2015/12/DockPaneLeftOf_Not_Used.png?resize=300%2C171" alt="DockPaneLeftOf Not Used" srcset="https://i1.wp.com/home.varlab.eu/wp-content/uploads/2015/12/DockPaneLeftOf_Not_Used.png?resize=300%2C171 300w, https://i1.wp.com/home visite site.varlab.eu/wp-content/uploads/2015/12/DockPaneLeftOf_Not_Used.png?w=406 406w” sizes=”(max-width: 300px) 100vw, 300px” data-recalc-dims=”1″ />
DockPaneLeftOf Not Used

It’s very simple to change this to having all toolbars in one row,
just replace the code above (in ‘MainFrm.cpp’) with this one:

source file (‘MainFrm.cpp’):
…………. 
m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar_Views3D.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar_Export2D.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar_Export3D.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_wndMenuBar);
DockPane(&m_wndToolBar_Export3D);
DockPaneLeftOf(&m_wndToolBar_Export2D, &m_wndToolBar_Export3D);
DockPaneLeftOf(&m_wndToolBar_Views3D, &m_wndToolBar_Export2D);
DockPaneLeftOf(&m_wndToolBar, &m_wndToolBar_Views3D);
………….

Now you have it in one row …. 🙂

DockPaneLeftOf Used
DockPaneLeftOf Used