PRB: LoadBarState Asserts While Restoring Two or More Floating Toolbars
ID: Q232845
|
The information in this article applies to:
-
The Microsoft Active Template Library (ATL) 3.0, included with:
-
Microsoft Visual C++, 32-bit Editions, versions 5.0, 6.0
SYMPTOMS
An application may cause an assertion failure while restoring settings for two or more floating toolbars using the LoadBarState method of CToolbar class.
CAUSE
This problem occurs when two or more floating toolbars have the same control ID.
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 Behavior
- Create a single document interface (SDI) application by using AppWizard.
- Add an m_wndToolBar2 member variable of type CToolbar to your CMainFrame class.
- 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");
- Create a handler WM_CLOSE message in CMainFrame class and add the following line at the beginning of the handler:
SaveBarState("One");
- Build the project.
- Run the project and float both the toolbars. Close the application.
- 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
© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Sreedhar Pelluru, Microsoft Corporation
Additional query words:
Keywords : kbMFC kbToolbar kbVC500 kbVC600 kbTools kbGrpMFCATL kbMFCCtrlBar
Version : WINDOWS:3.0
Platform : WINDOWS
Issue type : kbprb