How to customize title color for MFC ribbon bar

BorisM 41 Reputation points
2024-11-20T04:33:53.35+00:00

In an MFC MDI with ribbon bar project created with AppWizard, how to change background color of title area?

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,776 questions
0 comments No comments
{count} votes

Accepted answer
  1. Minxin Yu 12,176 Reputation points Microsoft Vendor
    2024-11-20T07:21:46.4933333+00:00

    Hi, @BorisM

    Create a MFC class that inherits Class CMFCVisualManagerOffice2007 and rewrite OnDrawRibbonCaption.

    Also, you need to redraw the title text and min/max/close buttons.

    virtual void OnDrawRibbonCaption(
        CDC* pDC,
        CMFCRibbonBar* pBar,
        CRect rectCaption,
        CRect rectText) override
    {
        
    	CWnd* pWnd = pBar->GetParent();
    	ASSERT_VALID(pWnd);
    	CDrawingManager dm(*pDC);
    	COLORREF clrBackground = RGB(0, 120, 215);
    	
    	dm.DrawRect(rectCaption, clrBackground, clrBackground);
    	//redraw text and max,min button
    	
    }
    
    BOOL CMFCApplicationApp::InitInstance()
    {
    ......
    CWinAppEx::InitInstance();
    CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMyVisualStyleClass));
    

    enter image description here

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.