Toolbar problem

I have written a Single Document Interface, MFC based program in VC++5. It has a lot of features and I want toolbar buttons for most of them so I have had to create a second toolbar. Everything works fine except that if my toolbar is floated and then closed using the X button, the View menu still shows it as ticked. I want to catch the toolbar being closed and untick the menu item. It’s just a detail but I am hoping to eventually sell my program and if this doesn’t work I think it looks unprofessional. I noticed that this does not happen with the main toolbar that is set up automatically in an SDI program. For this program I think that resizing of the window and undocking the toolbars is quite likely to be done by some users.

So having created the toolbar I added a corresponding entry in the View menu so under View there are items for Main toolbar, Second toolbar and Status bar.

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

1
2
3
4
BOOL m_graphicsBarVisible;

protected:
CToolBar m_wndToolBar,m_graphicsBar;


I added event handlers in MainFrm.cpp

1
2
3
4
5
6
7
8
9
10
void CMainFrame::OnViewToolbar2() 
{
	m_graphicsBarVisible=(!m_graphicsBarVisible);	
	ShowControlBar(&m_graphicsBar,m_graphicsBarVisible,FALSE);
}

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



and simply mirrored the standard creation statements in OnCreate() as shown in the edited version below

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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;
}


Last edited on
Topic archived. No new replies allowed.