Visual C++ 6.0 中 MFC 单文、多文档程序工具栏在 XP 风格下显示不正常的解决办法

    技术2025-05-20  43

    在 Visual C++ 6.0 中实现 XP 风格的程序界面一文中给出了 MFC 程序实现 XP 风格的一种方法,但美中不足的是对于单文档多文档程序来说,它在 XP 风格中会在左边出现一个白块。

     

     

    为了解决这个问题,网上给出了一个解决办法,具体链接忘了,知道的给个消息我加上去:-)

    下面是它的源代码,使用方法是将 CMainFrame型类成员 m_wndToolBar 将 CToolBar 类更换为 CGToolBar类即可解决此问题,以下是头文件和实现代码。非本人原创从网上得来:

    CGToolBar.h

    #if !defined(AFX_GTOOLBAR_H__25B0076B_2E75_4E66_8774_A71AB89E28A3__INCLUDED_) #define AFX_GTOOLBAR_H__25B0076B_2E75_4E66_8774_A71AB89E28A3__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 // GToolBar.h : header file // / // CGToolBar window class CGToolBar : public CToolBar { // Construction public: CGToolBar(); // Attributes public: // Operations public: // Overrides // ClassWizard generated virtual function overrides //{​{AFX_VIRTUAL(CGToolBar) //}}AFX_VIRTUAL // Implementation public: virtual ~CGToolBar(); void DrawGripper(CDC* pDC, const CRect& rect); void EraseNonClient(); virtual void DoPaint(CDC* pDC); // Generated message map functions protected: //{​{AFX_MSG(CGToolBar) // NOTE - the ClassWizard will add and remove member functions here. afx_msg void OnNcPaint(); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; / //{​{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_GTOOLBAR_H__25B0076B_2E75_4E66_8774_A71AB89E28A3__INCLUDED_)  

    CGToolBar.cpp

    // GToolBar.cpp : implementation file // #include "stdafx.h" #include "GToolBar.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif / // CGToolBar CGToolBar::CGToolBar() { } CGToolBar::~CGToolBar() { } BEGIN_MESSAGE_MAP(CGToolBar, CToolBar) //{​{AFX_MSG_MAP(CGToolBar) // NOTE - the ClassWizard will add and remove mapping macros here. ON_WM_NCPAINT() //}}AFX_MSG_MAP END_MESSAGE_MAP() / // CGToolBar message handlers void CGToolBar::OnNcPaint() { EraseNonClient(); } void CGToolBar::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 CGToolBar::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 CGToolBar::DrawGripper(CDC* pDC, const CRect& rect) { pDC->FillSolidRect( &rect, ::GetSysColor(COLOR_BTNFACE)); // Fill in the background. CToolBar::DrawGripper(pDC,rect); } 

    最新回复(0)