Click here to Skip to main content
15,881,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I appreciate it if someone can help me to diagnose the following problem: right now I'm trying to put two CMFCToolBars on a vs2010 SDI application. But they are having alignment problems now. The first toolbar falls nicely under the menubar, but the second seems always flying around. At most cases, it appears vertically attached to the left edge of the client area... I was playing this all day long and have to ask some ideas here. I believe this is a interesting question as I notice some people had this problems but there were only some likely solutions for VS6...

Thanks.

C++
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, CRect(1, 1, 1, 1), IDR_MAINFRAME_256 ) ||
		!m_wndToolBar.LoadToolBar( IDR_MAINFRAME_256 ))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}


	m_wndToolBar.SetWindowText(_T("test1"));
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);

	//DockControlBar((CControlBar *)&m_wndToolBar,AFX_IDW_DOCKBAR_LEFT, &rect);

	if (!m_wndToolBar1.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, CRect(1, 1, 1, 1), IDR_SORT )||
		!m_wndToolBar1.LoadToolBar(IDR_SORT))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}


	m_wndToolBar1.SetWindowText(_T("test"));
	m_wndToolBar1.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockPane(&m_wndToolBar);
	DockPane(&m_wndToolBar1);


What I have tried:

two CMFCToolBars docking problems in VS2010
Posted
Updated 6-May-19 10:13am
v4

Thanks Rick, I tried the function. It seems to me I have to force convert the CMFCToolBar* to CControlBar* as defined for the parameters. This results in a crash when the program calls DockControlBarLeftOf(this, m_wndToolBar1, m_wndToolBar). Is there any fix for this?
 
Share this answer
 
Comments
Rick York 6-May-19 16:07pm    
Did you try DockPaneLeftOf ? It takes pointers to CPane and that is what CMFCToolBar is derived from. This article might help.

Also, this should not be posted as a solution. It should be a question to my solution.
Hi Rick, I did not try DockPaneLeftOf(). However, I figured out a solution by manipulating few ID parameters when creating the toolbar in CreateEX(). What I did is using IDR_TOOLBAR1|AFX_IDW_TOOLBAR replacing a solo ID IDR_TOOLBAR1. I guess VS2010 takes it as a indication that the second CMFCToolBar ( m_toolbar1) is another 'prime' toolbar and put it in another line from left...


Thanks again.
 
Share this answer
 
Comments
Rick York 6-May-19 18:43pm    
I recommend downloading the FeaturePack samples for VS2010 and looking at the VisualStudioDemo sample app. It uses CMFCToolBars and calls DockPaneLeftOf in the CMainFrame class. What you did seems like a hack to me. In the sample app they use two IDs, one in a call to Create() and a different one in a call to LoadToolBar(). The one in the call to LoadToolBar is the ID of the bitmap resource. The other one (used in the call to Create) is the ID of the toolbar window and it is above the AFX_IDW_TOOLBAR value. That value is used for tool windows that can dock or float or what ever. You should not just OR a number with it to get the ID because that might not be unique and could cause problems.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900