【问题标题】:How to create a new visual style for a MFC ribbon?如何为 MFC 功能区创建新的视觉样式?
【发布时间】: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,它修复了错误。但它似乎并没有改变我的功能区栏的视觉风格。

【问题讨论】:

标签: user-interface visual-c++ mfc visual-styles


【解决方案1】:

随便用

CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMyVisualStyle));

【讨论】:

  • 什么样的错误?当您询问或报告问题时,请尽可能准确...我应该问您:“什么错误!”
  • 很抱歉。此错误:Compiler Error C2653 'identifier' : is not a class or namespace name The language syntax requires an class, structure, union, or namespace name here.
  • 需要包含头文件。
  • @naj:请edit您的问题包含相关信息。当您尝试使用在使用时尚未声明的类型时,会发出您看到的错误。您可能在尝试注册默认管理器的编译单元中缺少#include 指令。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-09-05
  • 1970-01-01
  • 1970-01-01
  • 2019-06-03
  • 2011-05-17
  • 2010-12-23
  • 1970-01-01
相关资源
最近更新 更多