Microsoft KB Archive/843490

= BUG: The gripper bar is drawn incorrectly when an MFC application uses Windows XP Visual Styles =

Article ID: 843490

Article Last Modified on 5/18/2007

-

APPLIES TO


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

-





SYMPTOMS
You may notice that the gripper bar on the toolbar is not drawn by using the background color of the toolbar when all the following conditions are true:
 * You are working on a computer that is running Microsoft Windows XP.
 * You are running a Single-document interface (SDI) application or a Multiple-document interface (MDI) application that was developed by using Microsoft Visual C++ 6.0 and the Microsoft Foundation Classes (MFC) libraries.
 * You are trying to implement Windows XP Visual Styles in your MFC application by adding a manifest file.

Note You do not notice this behavior if your application does not implement Windows XP Visual Styles. Also, you do not notice this behavior if you use CReBar class-derived control bars instead of CToolBar class-derived control bars.

The gripper bar is drawn with the color of the desktop or by using the background color of the application instead of the background color of the toolbar.



CAUSE
When your application uses a manifest file to implement Windows XP Visual Styles, the gripper bar on the toolbar is drawn by using the color of the desktop or by using the background color of your application.



RESOLUTION
To draw the gripper bar correctly, you must add a new class that is derived from the CToolBar class in your code, you must override different methods of the CToolBar class, and you must use the derived class member.

The following steps are an overview of what you will do in this section to resolve this problem:
 * 1) Sub-class the CToolBar class.
 * 2) Override the DrawGripper method and the DoPaint method of the base class.
 * 3) Handle the OnNcPaint message.
 * 4) Use the derived class member variable instead of the CToolBar class member variable.

To do this, follow these steps.

Note The following procedure is based on the 828548VC6 sample project that is mentioned in the &quot;More Information&quot; section.  Start Microsoft Visual Studio 6.0. Open the 828548VC6 project in Visual Studio 6.0. In the Workspace window, click the FileView tab. Expand the Header Files folder, and then double-click the Mainfrm.h file.

The Mainfrm.h file opens in the code editor.  Add the following code before the CMainFrame class definition. class CMyToolBar : public CToolBar { public: void DrawGripper(CDC* pDC, const CRect& rect); void EraseNonClient; virtual void DoPaint(CDC* pDC);

protected:

//AFX_MSG DECLARE_MESSAGE_MAP };   In the code editor, locate the following code. CToolBar   m_wndToolBar; </li>  Replace the code that you located in step 6 with the following code. CMyToolBar   m_wndToolBar; </li> In the Workspace window, expand the Source Files folder on the FileView tab, and then double-click the Mainfrm.cpp file.</li>  Add the following code after the compiler directives at the top of the code editor. ////////////////////////////////////////////////////// // CMyToolBar

BEGIN_MESSAGE_MAP(CMyToolBar, CToolBar) //AFX_MSG_MAP END_MESSAGE_MAP

void CMyToolBar::OnNcPaint {   EraseNonClient; } void CMyToolBar::EraseNonClient {

// Get window DC that is clipped to the non-client area. CWindowDC dc(this); CRect rectClient; GetClientRect(rectClient); CRect rectWindow; GetWindowRect(rectWindow); ScreenToClient(rectWindow); rectClient.OffsetRect(-rectWindow.left, -rectWindow.top); dc.ExcludeClipRect(rectClient);

// Draw the borders in the non-client area. rectWindow.OffsetRect(-rectWindow.left, -rectWindow.top); DrawBorders(&dc, rectWindow);

// Erase the parts that are not drawn. dc.IntersectClipRect(rectWindow); SendMessage(WM_ERASEBKGND, (WPARAM)dc.m_hDC);

// Draw the gripper in the non-client area. DrawGripper(&dc, rectWindow); }

void CMyToolBar::DoPaint(CDC* pDC) {   ASSERT_VALID(this); ASSERT_VALID(pDC);

// Paint inside the client area. CRect rect; GetClientRect(rect); DrawBorders(pDC, rect); DrawGripper(pDC, rect); }

void CMyToolBar::DrawGripper(CDC* pDC, const CRect& rect) {   pDC->FillSolidRect( &rect, ::GetSysColor(COLOR_BTNFACE)); // Fill in the background. CToolBar::DrawGripper(pDC,rect); } ///////////////////////////////////////////////////////////////////////// </li> Press F7 to build your application.</li> Press CTRL+F5 to run your application.</li></ol>

You do not notice the behavior that is mentioned in the &quot;Symptoms&quot; section.

<div class="status_section">

STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.

<div class="moreinformation_section">

Steps to reproduce the problem
To create an MFC-SDI application or an MFC-MDI application, follow these steps: <ol> Click Start, point to All Programs, and then point to Microsoft Visual Studio 6.0.</li> Click Microsoft Visual C++ 6.0. The Microsoft Visual Studio IDE for Visual C++ opens.</li> On the File menu, click New. The New dialog box appears.</li> On the Projects tab, click MFC AppWizard (exe).</li> In the Project name box, type 828548VC6 .</li> In the Location box, type C:\, and then click OK.</li> In the MFC AppWizard - Step 1 dialog box, click either Single document or Multiple documents, and then click Finish.</li> In the New Project Information dialog box, click OK.</li> Implement Windows XP Visual Styles: <ol style="list-style-type: lower-alpha;">  In a text editor such as Notepad, paste the following XML code. <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?> <assembly xmlns=&quot;urn:schemas-microsoft-com:asm.v1&quot; manifestVersion=&quot;1.0&quot;> Character Map application <dependentAssembly> <assemblyIdentity type=&quot;win32&quot; name=&quot;Microsoft.Windows.Common-Controls&quot; version=&quot;6.0.0.0&quot; processorArchitecture=&quot;X86&quot; publicKeyToken=&quot;6595b64144ccf1df&quot; language=&quot;*&quot; />      </dependentAssembly> </li> Save the document in the Debug folder. Name the document 828548VC6.exe.manifest. The Debug folder is located in the 828548VC6 folder of your project.

Note You must save the document in the Debug folder because the manifest file must exist in the same folder as the executable file.</li></ol> </li> <li>Press F7 to build the application.</li> <li>Press CTRL+F5 to run the application.</li></ol>

You notice the behavior that is mentioned in the &quot;Symptoms&quot; section.

back to the &quot;Resolution&quot; section

<div class="references_section">