How to save the docking position of CMFCToolBar toolbars?

  • Thread starter Thread starter Yan Yang
  • Start date Start date
Y

Yan Yang

Guest
I set toolbars to a specific docking position which is used as default state, the default statet of toolbars is saved in registry, which is loaded to position toolbars when user selects resetting toolbar to default position in the user interface. But I found that the order of toolbars is different from the default docking positions. Could you please let me know the problems in the code?

Thanks in advance.


int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
......
EnableDocking(CBRS_ALIGN_ANY);


// Default state of toolbars
DockPane(&m_wndDrillingCyclesToolBar);
DockPaneLeftOf(&m_wndFiveAxisToolBar, &m_wndDrillingCyclesToolBar);
DockPaneLeftOf(&m_wndMachiningToolBar, &m_wndFiveAxisToolBar);
DockPaneLeftOf(&m_wndGeometryToolBar, &m_wndMachiningToolBar);
DockPaneLeftOf(&m_wndBoundaryToolBar, &m_wndGeometryToolBar);
DockPaneLeftOf(&m_wndMainToolBar, &m_wndBoundaryToolBar);
DockPane(&m_wndUVSurfacesToolBar);
DockPaneLeftOf(&m_wndInspectionToolBar, &m_wndUVSurfacesToolBar);
DockPaneLeftOf(&m_wndAnalysisToolBar, &m_wndInspectionToolBar);
DockPaneLeftOf(&m_wndStandardViewsToolBar, &m_wndAnalysisToolBar);
DockPaneLeftOf(&m_wndGraphicsToolBar, &m_wndStandardViewsToolBar);
DockPaneLeftOf(&m_wndToolpathToolBar, &m_wndGraphicsToolBar);

// enable Visual Studio 2005 style docking window auto-hide behavior
EnableAutoHidePanes(CBRS_ALIGN_ANY);

// Set a style for the toolbars, etc.
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows7));
CDockingManager::SetDockingMode(DT_SMART);

// Save the default state of the toolbars
SaveBarState(CRegistryString::m_szToolbarSectionDefaults);

......
return 0;
}




void CMainFrame::OnResetToolBarsDefault()
{
LoadBarState(CRegistryString::m_szToolbarSectionDefaults);

this->Invalidate();
this->RecalcLayout();
this->RedrawWindow();

// Ensure all the toolbars are treated as horizontal bars before resetting.
EnableDocking(CBRS_ORIENT_HORZ);
}


void CMainFrame::SaveBarState(LPCTSTR lpszProfileName) const
{
const_cast<CMainFrame*>(this)->GetDockingManager()->SaveState(lpszProfileName);

CObList list;
const_cast<CMainFrame*>(this)->GetDockingManager()->GetPaneList(list, FALSE, NULL, FALSE);
if (list.GetCount() > 0)
{
POSITION pos = list.GetTailPosition();
while (pos != NULL)
{
CMFCToolBar* pToolBar = DYNAMIC_DOWNCAST(CMFCToolBar, list.GetPrev(pos));
if (pToolBar != nullptr)
{
pToolBar->SaveState(lpszProfileName);
}
}
}
}

void CMainFrame::LoadBarState(LPCTSTR lpszProfileName)
{
CObList list;
GetDockingManager()->GetPaneList(list, FALSE, NULL, FALSE);
if (list.GetCount() > 0)
{
POSITION pos = list.GetTailPosition();
while (pos != NULL)
{
CMFCToolBar* pToolBar = DYNAMIC_DOWNCAST(CMFCToolBar, list.GetPrev(pos));
if (pToolBar != nullptr)
{
pToolBar->LoadState(lpszProfileName);
}
}
}

GetDockingManager()->LoadState(lpszProfileName);
GetDockingManager()->SetDockState();
GetDockingManager()->ShowDelayShowMiniFrames(TRUE);
}

Continue reading...
 
Back
Top