Andrew Truckle
Andrew Truckle

Reputation: 19195

How to change the colours of a CMFCPropertySheetTabCtrl inside a CMFCPropertySheet

I derived CMFCPropertySheet class from and overrode the OnInitDialog function:

BOOL CDarkModeMFCPropertySheet::OnInitDialog()
{
    BOOL bResult = CMFCPropertySheet::OnInitDialog();

    if (IsUsingDarkMode())
    {
        DarkModeTools::EnableDarkModeForDialog(this);

        // Customize tab colors for dark mode
        m_wndTab.SetActiveTabColor(RGB(0, 120, 212));       // Active tab background (blue)
        m_wndTab.SetTabBkColor(RGB(32, 32, 32));            // Inactive tab background (dark gray)
        m_wndTab.SetTabTextColor(RGB(200, 200, 200));       // Inactive tab text (light gray)
        m_wndTab.SetActiveTabTextColor(RGB(255, 255, 255)); // Active tab text (white)
        // m_wndTab.SetTabBorderColor(RGB(64, 64, 64));     // Tab border (darker gray)
    }

    return bResult;
}

I have examined the MFC sources and the variable m_wndTab is defined as:

CMFCPropertySheetTabCtrl  m_wndTab;

The CMFCPropertySheetTabCtrl has all the functions I am trying to use and from the documentation it implies I should be able to colour the tab control. But alas, it is not working. Why?


Update

In the comments it was suggested that I adjust the m_bFlat variable, which is protected. IN the end I did this:

m_wndTab.ModifyTabStyle(CMFCTabCtrl::STYLE_FLAT);

Now, when I trace into that call, it does:

BOOL CMFCTabCtrl::ModifyTabStyle(Style style)
{
    ASSERT_VALID(this);

    m_bFlat = (style == STYLE_FLAT);
    m_bIsOneNoteStyle = (style == STYLE_3D_ONENOTE);
    m_bIsVS2005Style = (style == STYLE_3D_VS2005);
    m_bHighLightTabs = m_bIsOneNoteStyle;
    m_bLeftRightRounded = (style == STYLE_3D_ROUNDED || style == STYLE_3D_ROUNDED_SCROLL);

    SetScrollButtons();
    SetTabsHeight();

    return TRUE;
}

So it does change the m_bFlat variable and I confirm it is now TRUE. But, despite calling this code, no changes have been made to my property sheet colours.


Possible Alternative

Create a new Visual Manager class and override:

CMFCVisualManager::GetTabFrameColors

Override this function in a derived class if you want to customize the set of colors that the framework uses when it draws a tab window.

Worth investigating!

Upvotes: 1

Views: 65

Answers (1)

Andrew Truckle
Andrew Truckle

Reputation: 19195

I ended up using TabCtrl. It has a lot of features.

So now I have coloured tabs:

Sample dialog using TabCtrl

And, as for the Outlook bar on property sheets, I did this:

#pragma once
#include <afxvisualmanagerwindows.h>

// CDarkModeMFCVisualManagerWindows command target

class CDarkModeMFCVisualManagerWindows : public CMFCVisualManagerWindows
{
    DECLARE_DYNCREATE(CDarkModeMFCVisualManagerWindows)
    
public:
    void OnFillBarBackground(CDC* pDC, CBasePane* pBar, CRect rectClient, CRect rectClip, BOOL bNCArea = FALSE) override
    {
        if (DarkModeTools::InvokeUseDarkModeFunction())
        {
            pDC->FillSolidRect(rectClient, DarkModeTools::kDarkControlBackgroundColor);
            return;
        }
    
        __super::OnFillBarBackground(pDC,pBar,rectClient,rectClip,bNCArea);
    }
    
};
    
IMPLEMENT_DYNCREATE(CDarkModeMFCVisualManagerWindows, CMFCVisualManagerWindows)

I use that manager in InitInstance. Now the outlook bar is coloured as I want:

OutlookBar with custom back colour

So, not a direct answer to my question, but a satisfactory workaround.

Upvotes: 0

Related Questions