Changing text color of ribbon button

2019-08-11 16:36发布

问题:

I'm having an issue in VS2013-15 where my buttons' font colour is a shade of grey rather than black.

Here is what the buttons look like currently:

Some of the text seems to change to the desired colour when hovered over. However, some don't changed even when hovered:

Any help would be greatly appreciated. Thanks.

回答1:

I managed to fix it using Barmak's answer. The Windows 7 theme is the problem.

To fix, you have 2 options.

Option 1


Change the theme your program uses

This is a lazy work around. Just switch your visual manager from CMFCVisualManagerWindows7 to one of the other visual managers.


Option 2


Override the OnUpdateSystemColors() function

First off you'll need a new class that inherits CMFCVisualManagerWindows7:

class Win7VM : public CMFCVisualManagerWindows7
{

}; 

Then you'll need to call DECLARE_DYNCREATE as the object is created dynamically at runtime.

class Win7VM : public CMFCVisualManagerWindows7
{
    DECLARE_DYNCREATE(Win7VM);  
}; 

Next, you'll need to implement the class.

class Win7VM : public CMFCVisualManagerWindows7
{
    DECLARE_DYNCREATE(Win7VM)

    virtual void OnUpdateSystemColors()
    {
        CMFCVisualManagerWindows7::OnUpdateSystemColors();
        m_clrRibbonPanelCaptionText = RGB(0, 0, 0);
    }
};

After that, you need to call IMPLEMENT_DYNCREATE separate to your class implementation, in global scope.

IMPLEMENT_DYNCREATE(Win7VM, CMFCVisualManagerWindows7);

Finally, we need to change our usage of CMFCVisualManagerWindows7 to that of our new class:

CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(Win7VM));



标签: c++ windows mfc