BUG: The gripper bar is drawn incorrectly when an MFC application uses Windows XP Visual Styles (843490)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0, when used with:
- the operating system: Microsoft Windows XP
SYMPTOMSYou 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. CAUSEWhen 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. RESOLUTIONTo 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: - Sub-class the
CToolBar class.
- Override the DrawGripper method and the DoPaint method of the
base class.
- Handle the OnNcPaint message.
- 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 " More
Information" 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(CMyToolBar)
afx_msg void OnNcPaint();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
}; - In the code editor, locate the following code.
CToolBar m_wndToolBar; - Replace the code that you located in step 6 with
the following code.
CMyToolBar m_wndToolBar; - In the Workspace
window, expand the Source Files folder on the FileView tab, and then double-click
the Mainfrm.cpp file.
- Add the following code after
the compiler directives at the top of the code editor.
//////////////////////////////////////////////////////
// CMyToolBar
BEGIN_MESSAGE_MAP(CMyToolBar, CToolBar)
//{{AFX_MSG_MAP(CMyToolBar)
ON_WM_NCPAINT()
//}}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);
}
///////////////////////////////////////////////////////////////////////// - Press F7 to build your application.
- Press CTRL+F5 to run your application.
You do not notice
the behavior that is mentioned in the "Symptoms" section. STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section. REFERENCESFor more information, visit the following Microsoft
Developer Network (MSDN) Web sites:
Modification Type: | Major | Last Reviewed: | 6/22/2004 |
---|
Keywords: | kbgraphic kbdraw kbRebarCtrl kbMDI kbAppWizard kbcode kbbug KB843490 kbAudDeveloper |
---|
|