Floating toolbar problem

I am trying to fix a toolbar related problem. My program is Single Document Interface, MFC based, written in VC++ 5 and I have created a second toolbar. Either toolbar can be shown or hidden, as usual, via the View menu and they are shown as checked or unchecked. The problem comes when my toolbar is floated and then closed by the X button instead of from the menu. When the View menu is then opened there is still a tick against the second toolbar. I want to detect the fact that the floating toolbar was closed and probably make use of GetMenu() to clear the checkmark.

In MainFrm.h I have declared the second toolbar alongside the main one and added a global shown / hidden flag.


BOOL m_graphicsBarVisible;

protected:
CToolBar m_wndToolBar,m_graphicsBar;


In MainFrm.cpp I have mirrored the standard creation statements in OnCreate() and then added OnViewToolbar2 and OnUpdateViewToolbar2.


int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{

   if (!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
   {
      TRACE0("Failed to create toolbar\n");
      return -1;
   }

   if (!m_graphicsBar.Create(this) || !m_graphicsBar.LoadToolBar(IDR_GRAPHICS))
   {
      TRACE0("Failed to create second toolbar\n");
      return -1;
   }

   m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS |      CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
   m_graphicsBar.SetBarStyle(m_graphicsBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
	
   m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
   m_graphicsBar.EnableDocking(CBRS_ALIGN_ANY);
   EnableDocking(CBRS_ALIGN_ANY);
   DockControlBar(&m_wndToolBar);
   DockControlBar(&m_graphicsBar);
	
   m_graphicsBarVisible=TRUE;
   return 0;

}

void CMainFrame::OnViewToolbar2() 
{
   m_graphicsBarVisible=(!m_graphicsBarVisible);	
   ShowControlBar(&m_graphicsBar,m_graphicsBarVisible,FALSE);
}

void CMainFrame::OnUpdateViewToolbar2(CCmdUI* pCmdUI) 
{
   pCmdUI->SetCheck(m_graphicsBarVisible);	
}

Last edited on
Topic archived. No new replies allowed.