Microsoft KB Archive/251232

= BUG: MFC Dockable Toolbars Do Not Paint Correctly with the CBRS_ALIGN_TOP Style =

Article ID: 251232

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 5.0 Enterprise Edition

 Microsoft Visual C++ 5.0 Professional Edition

 Microsoft Visual C++ 6.0 Enterprise Edition

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

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

-

<div class="notice_section">

This article was previously published under Q251232

<div class="symptoms_section">

SYMPTOMS
When you create a toolbar using the MFC CToolBar class and if you used the CBRS_ALIGN_TOP style, then the toolbar may not paint properly. You see dark spots on the right most and left most edges of the toolbar. This repainting problem is more obvious if you undock the toolbar and dock it again.

<div class="resolution_section">

RESOLUTION
Use the CBRS_TOP style instead of CBRS_ALIGN_TOP. CBRS_TOP is defined as the following:


 * 1) define CBRS_TOP           (CBRS_ALIGN_TOP|CBRS_BORDER_BOTTOM)

Thus, if you use CBRS_TOP or use CBRS_ALIGN_TOP along with CBRS_BORDER_BOTTOM, it works correctly and as expected.

<div class="status_section">

STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

<div class="moreinformation_section">

MORE INFORMATION
Note that the CreateEx member function of CToolBar, takes the CBRS_ALIGN_TOP style as the default. Therefore, if you had code like the following then you see this behavior.

if (!m_wndToolBar.CreateEx(this) ||       !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) {       TRACE0("Failed to create toolbar\n"); return -1;     // fail to create }

In an AppWizard generated application, you do not see this behavior because it uses the CBRS_TOP style.

Steps to Reproduce Behavior
<ol> Generate a new MFC SDI or MDI application.</li>  Go to Mainfrm.cpp, CMainFrame::OnCreate and replace the CToolBar::CreateEx call to look like the following:

if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||       !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) {       TRACE0("Failed to create toolbar\n"); return -1;     // fail to create }

Replace CBRS_TOP with CBRS_ALIGN_TOP. </li> Build and run the application. Drag the toolbar out, move it around and dock it back. Observe that it does not paint properly.</li></ol>

<div class="references_section">