In C++/Win32, it works for me if I hancle WM_CTLCOLOR* messages in the StatusBar, which is the parent of ComboBox (I must subclass it with SetWindowSubclass)
Darkmode combo on statusbar panes
I have two regular CComboBox
controls (dropdown list style), and I have superimposed them on two statusbar panes:
This is how I create one of the combo boxes:
void CChristianLifeMinistryEditorDlg::InitStatusBarPageBreakCombo()
{
CFont* pFont = m_StatusBar.GetFont();
CRect rcPane;
m_StatusBar.GetItemRect(to_underlying(EnumStatusBarPane::PageBreaks), &rcPane);
rcPane.left += kStatusBarIconWidth;
m_cbStatusBarPageBreaks.Create(WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_DROPDOWNLIST,
rcPane, &m_StatusBar, IDC_COMBO_STATUSBAR_PAGE_BREAKS);
m_cbStatusBarPageBreaks.SetFont(pFont);
if (IsUsingDarkMode())
{
DarkModeTools::ApplyThemeToControl(&m_cbStatusBarPageBreaks);
}
list<UINT> listIDs;
listIDs.push_back(IDS_STR_PAGE_BREAK_NONE);
listIDs.push_back(IDS_STR_PAGE_BREAK_1WEEK);
listIDs.push_back(IDS_STR_PAGE_BREAK_2WEEKS);
listIDs.push_back(IDS_STR_PAGE_BREAK_3WEEKS);
listIDs.push_back(IDS_STR_PAGE_BREAK_4WEEKS);
for (const UINT& uID : listIDs)
{
CString strPageBreakMode, strPageBreakComboText;
VERIFY(strPageBreakMode.LoadString(uID));
strPageBreakComboText.Format(IDS_TPL_PAGE_BREAKS, (LPCTSTR)strPageBreakMode);
m_cbStatusBarPageBreaks.AddString(strPageBreakComboText);
}
m_cbStatusBarPageBreaks.SetCurSel(to_underlying(m_ePageBreakMode));
CPngImage pngImage;
LOAD_LIGHT_THEME_PNG(pngImage, IDB_PNG_PAGE_BREAKS);
m_StatusBar.SetPaneIcon(to_underlying(EnumStatusBarPane::PageBreaks), pngImage);
}
As you can see, the statusbar is set as the parent. And the statusbar is owner draw.
Everything is fine, except when the droplist shows:
If I had the combo on the dialog as a resource it will colour properly because the OnCtrlColor
handler is triggered. But for some reason things are not working for these combos.
As for theming, I use DarkMode_CFD
for the combo and this for the drop-list:
if (className == L"ComboBox")
{
COMBOBOXINFO cbi{};
cbi.cbSize = sizeof(COMBOBOXINFO);
if (GetComboBoxInfo(pControl->GetSafeHwnd(), &cbi) && cbi.hwndList)
{
SetWindowTheme(cbi.hwndList, szDarkMode_Explorer, nullptr);
}
}
Why doesn't it work for the droplist bits on my combos on the statusbar?