1

The application is using the Windows 7 ribbon style by default:

CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007));

i want to create a new Visual Style where i implemented different colors, so i created the class CMyVisualStyle that inherits from CMFCVisualManagerOffice2007. This is the .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);

This is the .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);
}

And i edited this in the the mainframe.cpp:

CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMyVisualStyle::GetThisClass()));
//CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007));

But it seems like the RUNTIME_CLASS can't find my class, error: Compiler Error C2653 'identifier' : is not a class or namespace name The language syntax requires a class, structure, union, or namespace name here.

Update: i included the MyVisualStyle.h and it fixed the error. But it doesn't seem to change the Visual style of my ribbon bar.

  • 1
    [Use `RUNTIME_CLASS` with the **name of the class** \[...\]](https://learn.microsoft.com/en-us/cpp/mfc/accessing-run-time-class-information?view=vs-2019#to-use-the-runtime_class-macro). `CMyVisualStyle::GetThisClass()` is not the name of a class. – IInspectable Nov 28 '19 at 12:12
  • Why is your `IMPLEMENT_DYNCREATE` inside a `#define`? It's a macro you should have called. – Dan Sep 19 '22 at 18:40

1 Answers1

1

Just use

CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMyVisualStyle));
xMRi
  • 14,982
  • 3
  • 26
  • 59
  • What kind of error? When you ask, or report problems, be as precise as possible... I should have to ask you about: "What error!" – xMRi Nov 29 '19 at 10:15
  • Sorry about that. This error: Compiler Error C2653 'identifier' : is not a class or namespace name The language syntax requires a class, structure, union, or namespace name here. – Najat Ismail Nov 29 '19 at 10:23
  • 1
    Need to include the header file. – xMRi Nov 29 '19 at 11:39
  • 1
    @naj: Please [edit](https://stackoverflow.com/posts/59087697/edit) your question to include the relevant information. The error you are seeing is issued when you are trying to use a type, that hasn't been declared at the point of use. You are probably missing an `#include` directive in the compilation unit where you are trying to register the default manager. – IInspectable Nov 29 '19 at 11:40