Microsoft KB Archive/232845

From BetaArchive Wiki

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
    • Microsoft Visual C++ 6.0 Standard Edition
    • Microsoft Visual C++ .NET 2002 Standard Edition
  • Microsoft Visual C++ .NET 2003 Standard Edition



This article was previously published under Q232845

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.

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.

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.

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.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to reproduce the behavior

  1. Create a single document interface (SDI) application by using AppWizard.
  2. Add an m_wndToolBar2 member variable of type CToolbar to your CMainFrame class.
  3. 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");
    
                            
  4. Create a handler WM_CLOSE message in CMainFrame class and add the following line at the beginning of the handler:

        SaveBarState("One");    
                            
  5. Build the project.
  6. Run the project and float both the toolbars. Close the application.
  7. Run the application again to see the assertion.

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).

REFERENCES

Keywords: kbhowto kbtoolbar kbprb kbmfcctrlbar KB232845