【发布时间】:2020-03-24 01:01:03
【问题描述】:
应用程序默认使用 Windows 7 功能区样式:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007));
我想创建一个新的视觉样式,我在其中实现了不同的颜色,所以我创建了继承自 CMFCVisualManagerOffice2007 的类 CMyVisualStyle。
这是.h:
class CMyVisualStyle : public CMFCVisualManagerOffice2007
{
DECLARE_DYNCREATE(CMyVisualStyle)
public:
CMyVisualStyle();
~CMyVisualStyle();
virtual COLORREF OnDrawRibbonPanel(CDC* pDC, CMFCRibbonPanel* pPanel, CRect rectPanel, CRect rectCaption);
virtual void OnDrawRibbonCategory(CDC* pDC, CMFCRibbonCategory* pCategory, CRect rectCategory);
这是.cpp:
#include "stdafx.h"
#include "MyVisualStyle.h"
#define IMPLEMENT_DYNCREATE(CMyVisualStyle, CMFCVisualManagerOffice2007)
CMyVisualStyle::CMyVisualStyle()
{
}
CMyVisualStyle::~CMyVisualStyle()
{
}
COLORREF CMyVisualStyle::OnDrawRibbonPanel(CDC* pDC, CMFCRibbonPanel* pPanel, CRect rectPanel, CRect rectCaption)
{
CBrush br(RGB(0, 0, 255));
pDC->FillRect(rectPanel, &br);
return RGB(0, 255, 0);
}
void CMyVisualStyle::OnDrawRibbonCategory(CDC* pDC, CMFCRibbonCategory* pCategory, CRect rectCategory)
{
CBrush br(RGB(255, 0, 0));
pDC->FillRect(rectCategory, &br);
//return RGB(0, 255, 0);
}
我在 mainframe.cpp 中编辑了这个:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMyVisualStyle::GetThisClass()));
//CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007));
但似乎RUNTIME_CLASS 找不到我的班级,错误:
编译器错误 C2653 'identifier' : is not a class or namespace name The language syntax requires an class, structure, union, or namespace name here.
更新:我包含了MyVisualStyle.h,它修复了错误。但它似乎并没有改变我的功能区栏的视觉风格。
【问题讨论】:
-
Use
RUNTIME_CLASSwith the name of the class [...]。CMyVisualStyle::GetThisClass()不是类的名称。
标签: user-interface visual-c++ mfc visual-styles