Discussion:
Difficulties in creating multiple toolbars
(too old to reply)
JiiPee
2016-01-02 00:35:35 UTC
Permalink
I am trying to add a simple second toolbar on the right hand side of the
default toolbar. How is this so difficult? :)

It a bit long post, so shortly: if somebody knows an example code where
two toolbars are added (in the latest VS versions) I could just check
how they do it. But if not, here is my "story":

I get these problems:
1) After I launch the the program second time both have the second
toolbars title "Second toolbar" (on first run they both have correct titles)

2) The toolbars do not keep their position after I close the program and
run again ( If I have only one toolbar, it remembers correctly its
position).

3) sometimes when I drag one of the toolbars it suddenly jumps a lot to
the right ... so there is a gap between my mouse and the toolbar. It
moves, but my mouse is not anymore in its title but there is a large gap.

Seems like the toolbar ID s somehow are mixed up.
My question is: how do I create a SDI application with two toolbars in
it? I cannot even find example when I google...

It saves the toolbar information to registry and loads toolbars
positions from there. Does this somehow conflict now with my code?

Here is my code if somebody can find the error/reason, thank you.
m_wndSecondToobar is my second toolbar and I have commented "ADDED" the
code I added to the original Wizard code. This is a SDI project created
by Wizard, VS 2010:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWndEx::OnCreate(lpCreateStruct) == -1)
return -1;

BOOL bNameValid;

OnApplicationLook(theApp.m_nAppLook);

if (!m_wndMenuBar.Create(this))
{
TRACE0("Failed to create menubar\n");
return -1; // fail to create
}

m_wndMenuBar.SetPaneStyle(m_wndMenuBar.GetPaneStyle() |
CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY);

// prevent the menu bar from taking the focus on activation
CMFCPopupMenu::SetForceMenuFocus(FALSE);
// first toolbar
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT,
WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS
| CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(theApp.m_bHiColorIcons ?
IDR_MAINFRAME_256 : IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
// ADDED: second toolbar
if (!m_wndSecondToobar.CreateEx(this, TBSTYLE_FLAT,
WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS
| CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndSecondToobar.LoadToolBar(IDR_TOOLBAR_CALCULATIONS)) //
IDR_MAINFRAME IDR_TOOLBAR_CALCULATIONS
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}

CString strToolBarName;
bNameValid = strToolBarName.LoadString(IDS_TOOLBAR_STANDARD);
ASSERT(bNameValid);
m_wndSecondToobar.SetWindowText(_T("Second toolbar")); // ADDED
m_wndToolBar.SetWindowText(strToolBarName);

CString strCustomize;
bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);
ASSERT(bNameValid);

if (!m_wndStatusBar.Create(this))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
m_wndStatusBar.SetIndicators(indicators, sizeof(indicators) /
sizeof(UINT));

m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndSecondToobar.EnableDocking(CBRS_ALIGN_ANY); // ADDED
EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_wndMenuBar);

DockPane(&m_wndToolBar);
DockPaneLeftOf(&m_wndSecondToobar, &m_wndToolBar); // ADDED
// enable Visual Studio 2005 style docking window behavior
CDockingManager::SetDockingMode(DT_SMART);
// enable Visual Studio 2005 style docking window auto-hide behavior
EnableAutoHidePanes(CBRS_ALIGN_ANY);
// Enable toolbar and docking window menu replacement
EnablePaneMenu(TRUE, ID_VIEW_CUSTOMIZE, strCustomize, ID_VIEW_TOOLBAR);
// enable quick (Alt+drag) toolbar customization
CMFCToolBar::EnableQuickCustomization();

return 0;
}
o***@gmail.com
2018-01-02 15:08:23 UTC
Permalink
Post by JiiPee
I am trying to add a simple second toolbar on the right hand side of the
default toolbar. How is this so difficult? :)
It a bit long post, so shortly: if somebody knows an example code where
two toolbars are added (in the latest VS versions) I could just check
1) After I launch the the program second time both have the second
toolbars title "Second toolbar" (on first run they both have correct titles)
2) The toolbars do not keep their position after I close the program and
run again ( If I have only one toolbar, it remembers correctly its
position).
3) sometimes when I drag one of the toolbars it suddenly jumps a lot to
the right ... so there is a gap between my mouse and the toolbar. It
moves, but my mouse is not anymore in its title but there is a large gap.
Seems like the toolbar ID s somehow are mixed up.
My question is: how do I create a SDI application with two toolbars in
it? I cannot even find example when I google...
It saves the toolbar information to registry and loads toolbars
positions from there. Does this somehow conflict now with my code?
Here is my code if somebody can find the error/reason, thank you.
m_wndSecondToobar is my second toolbar and I have commented "ADDED" the
code I added to the original Wizard code. This is a SDI project created
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWndEx::OnCreate(lpCreateStruct) == -1)
return -1;
BOOL bNameValid;
OnApplicationLook(theApp.m_nAppLook);
if (!m_wndMenuBar.Create(this))
{
TRACE0("Failed to create menubar\n");
return -1; // fail to create
}
m_wndMenuBar.SetPaneStyle(m_wndMenuBar.GetPaneStyle() |
CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY);
// prevent the menu bar from taking the focus on activation
CMFCPopupMenu::SetForceMenuFocus(FALSE);
// first toolbar
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT,
WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS
| CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(theApp.m_bHiColorIcons ?
IDR_MAINFRAME_256 : IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
// ADDED: second toolbar
if (!m_wndSecondToobar.CreateEx(this, TBSTYLE_FLAT,
WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS
| CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndSecondToobar.LoadToolBar(IDR_TOOLBAR_CALCULATIONS)) //
IDR_MAINFRAME IDR_TOOLBAR_CALCULATIONS
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
CString strToolBarName;
bNameValid = strToolBarName.LoadString(IDS_TOOLBAR_STANDARD);
ASSERT(bNameValid);
m_wndSecondToobar.SetWindowText(_T("Second toolbar")); // ADDED
m_wndToolBar.SetWindowText(strToolBarName);
CString strCustomize;
bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);
ASSERT(bNameValid);
if (!m_wndStatusBar.Create(this))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
m_wndStatusBar.SetIndicators(indicators, sizeof(indicators) /
sizeof(UINT));
m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndSecondToobar.EnableDocking(CBRS_ALIGN_ANY); // ADDED
EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_wndMenuBar);
DockPane(&m_wndToolBar);
DockPaneLeftOf(&m_wndSecondToobar, &m_wndToolBar); // ADDED
// enable Visual Studio 2005 style docking window behavior
CDockingManager::SetDockingMode(DT_SMART);
// enable Visual Studio 2005 style docking window auto-hide behavior
EnableAutoHidePanes(CBRS_ALIGN_ANY);
// Enable toolbar and docking window menu replacement
EnablePaneMenu(TRUE, ID_VIEW_CUSTOMIZE, strCustomize, ID_VIEW_TOOLBAR);
// enable quick (Alt+drag) toolbar customization
CMFCToolBar::EnableQuickCustomization();
return 0;
}
same issue for me
did u find any correct to this?

Continue reading on narkive:
Loading...