Microsoft KB Archive/232845

= LoadBarState assert fails when restoring two or more floating toolbars =

Article ID: 232845

Article Last Modified on 4/22/2005

-

APPLIES TO

 Microsoft ActiveX Template Library 3.0, when used with:  Microsoft Visual C++ 5.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 5.0 Professional Edition

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2002 Standard Edition</li></ul> </li> Microsoft Visual C++ .NET 2003 Standard Edition</li></ul>

-

<div class="notice_section">

This article was previously published under Q232845

<div class="notice_section">

Note Microsoft Visual C++ NET (2002) supported both the managed code model that is provided by the .NET Framework and the unmanaged native Windows code model. The information in this article applies to unmanaged Visual C++ code only.

<div class="symptoms_section">

SYMPTOMS
An application may cause an assertion failure while restoring settings for two or more floating toolbars by using the LoadBarState method of CToolbar class.

<div class="cause_section">

CAUSE
This problem occurs when two or more floating toolbars have the same child window ID. If you do not specify a toolbar’s child window ID as the last parameter to CToolBar::Create or CToolBar::CreateEx methods, it defaults to AFX_IDW_TOOLBAR.

<div class="resolution_section">

RESOLUTION
Pass a unique control ID while calling Create or CreateEx for each toolbar, and then change the profile name in the LoadBarState and SaveBarState calls.

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

Steps to reproduce the behavior
<ol> Create a single document interface (SDI) application by using AppWizard.</li> Add an m_wndToolBar2 member variable of type CToolbar to your CMainFrame class.</li>  Add the following code to OnCreate method of CMainFrame class: if (!m_wndToolBar2.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||        !m_wndToolBar2.LoadToolBar(IDR_MAINFRAME)) {       TRACE0("Failed to create toolbar\n"); return -1;     // Fail to create. }   m_wndToolBar2.EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar2); LoadBarState("One");

</li>  Create a handler WM_CLOSE message in CMainFrame class and add the following line at the beginning of the handler: SaveBarState("One"); </li> Build the project.</li> Run the project and float both the toolbars. Close the application.</li> Run the application again to see the assertion.</li></ol>

To create a new resource ID, on the View menu, click Resource Symbols, and then click New in the Symbols dialog box. Pass this resource ID as the last parameter to CToolbar's Create or CreateEx member function in CMainFrame's OnCreate method. You do not need to do this for the first toolbar, which can have a default resource ID (AFX_IDW_TOOLBAR).

<div class="references_section">