From: David Webber on
Are there any examples showing how to add a second (etc) toolbar to a
(tabbed) MDI program created with the AppWizard?

The documentation I've found of CMFCToolBar is a bit sparse. An example
creating multiple CMFCToolBars would be very helpful, but I haven't found
much in the new revamped help system :-(

In more detail:

If I add a second toolbar following the supplied code which adds the
standard one, it works fine the first time I use the program. But on
subsequent runs, somewhere deep in the guts of CMDIFrameWndEx, it is getting
confused when trying to load the toolbar state from the registry, and I'm
getting more toolbars than I create, without the proper buttons.

(I can show some code, but I'm just wondering about examples before
requesting debugging help!) The rots of my problem are given below.

Dave
===================

1. In the good old days:

CToolBar data was stored at

HKEY_CURRENT_USER\Software\<company>\<program>\ToolBar-Summary\
....\<program>\ToolBar-Bar0\
....\<program>\ToolBar-Bar1\
....

and accessed with

CFrameWnd::LoadBarState( _T("ToolBar") );

This, I think, had to be called explicitly from one's CMainFrame::OnCreate()
as it wasn't called from within CMDIFrameWnd::OnCreate(). But it worked!

2. Nowadays:

There's a lot more in the registry, at

HKEY_CURRENT_USER\Software\<company>\<program>\ToolBar-Summary\
....\<program>\Workspace\MFCToolBar-nnnn
....\<program>\Workspace\BasePane-nnnn
....\<program>\Workspace\Pane-nnnn

and it all seems to be handled automatically (ie loaded) from deep within
CMDIFrameWndEx::OnCreate(). So obviously, how one creates the toolbars must
concur with its expectations. The documentation seems very terse, and thus
far I'm clearly failing :-(


====================








From: David Webber on
Curiouser and curiouser.

I seem to have it working, but have no idea why or how.

In my MainFrm.cpp the AppWizard wrote at the top

=====
const int iMaxUserToolbars = 10;
const UINT uiFirstUserToolBarId = AFX_IDW_CONTROLBAR_FIRST + 40;
const UINT uiLastUserToolBarId = uiFirstUserToolBarId + iMaxUserToolbars -
1;
=====

I added for the moment

==============
const UINT IDW_TBAR_NOTE = ....;
==============

[Value to be discussed below.]


In CmainFrame::OnCreate():

After the AppWizard's

=======
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
}
......
// Allow user-defined toolbars operations:
InitUserToolbars(NULL, uiFirstUserToolBarId, uiLastUserToolBarId);
======

I added:

======
CRect rectBorders( 1, 1, 1, 1 );

if (!m_wndToolBarNote.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE |
CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,
rectBorders, IDW_TBAR_NOTE ) ||
!m_wndToolBarNote.LoadToolBar(theApp.m_bHiColorIcons ?
IDR_TBAR_NOTE_256: IDR_TBAR_NOTE ) )
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
======

with all resource IDs and my second CMFCToolBar member (m_wndToolBarNote)
all present and correct.

IT ALL SEEMS TO HINGE ON THE CHILD WINDOW ID (IDW_TBAR_NOTE).
My first guess was that this should be set to uiFirstUserToolBarId - the
name sort of suggests that. But that Gave me all the problems I have
outlined.

In the old days I used 0xE804 as my first toolbar child window ID - so I
tried it. And it works - at least to the extent that I can move it
around, close the program, and next time it appears where I left it.

But 0xE804 is not even in the suggested range - as
uiFirstUserToolBarId=0xE840

Can anybody help me understand what is going on????

Dave
--
David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm





From: David Webber on


"David Webber" <dave(a)musical-dot-demon-dot-co.uk> wrote in message
news:uiYqQRjDLHA.1368(a)TK2MSFTNGP06.phx.gbl...

> But 0xE804 is not even in the suggested range - as
> uiFirstUserToolBarId=0xE840

Sorry 0xE828 - was getting decimals and hexadecimals mixed. But the point
remains.

Dave

--
David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm