admin管理员组文章数量:1317898
I am looking at this GitHub project:
It refers to using undocumented API to use dark mode in Win32 projects (if the OS is of a certain version).
I find that it works, but not for status bars (and a few other controls). I tried:
SetWindowTheme(m_StatusBar.GetSafeHwnd(), L"DarkMode_Explorer", nullptr);
But it made no difference:
The controls I have issues with are:
- Menu bar
- Tool bar
- Check box
- Group box
- Combo - Droplist
- Date picker
- Calendar
- Property Grid
I include my OnCtlColor
handler for completeness (in-case it helps):
HBRUSH CResizingDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = __super::OnCtlColor(pDC, pWnd, nCtlColor);
if (theApp.GetNumberSetting(L"Options", L"Theme_UseDarkMode", false))
{
constexpr COLORREF darkBkColor = 0x383838;
constexpr COLORREF darkTextColor = 0xFFFFFF;
// Return a solid brush with the dark background color
static HBRUSH hbrBackground = CreateSolidBrush(RGB(45, 45, 45));
hbr = hbrBackground;
// If you need to customize specific controls, add conditions
switch (nCtlColor)
{
case CTLCOLOR_DLG: // Dialog background
case CTLCOLOR_STATIC: // Static text
case CTLCOLOR_EDIT: // Edit control
case CTLCOLOR_LISTBOX: // Listbox
pDC->SetTextColor(darkTextColor); // Light text
pDC->SetBkColor(darkBkColor); // Dark background
break;
break;
case CTLCOLOR_SCROLLBAR: // Scrollbars
case CTLCOLOR_BTN: // Buttons
default:
// You can add specific cases here if needed
break;
}
}
return hbr;
}
I am looking at this GitHub project:
https://github/ysc3839/win32-darkmode
It refers to using undocumented API to use dark mode in Win32 projects (if the OS is of a certain version).
I find that it works, but not for status bars (and a few other controls). I tried:
SetWindowTheme(m_StatusBar.GetSafeHwnd(), L"DarkMode_Explorer", nullptr);
But it made no difference:
The controls I have issues with are:
- Menu bar
- Tool bar
- Check box
- Group box
- Combo - Droplist
- Date picker
- Calendar
- Property Grid
I include my OnCtlColor
handler for completeness (in-case it helps):
HBRUSH CResizingDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = __super::OnCtlColor(pDC, pWnd, nCtlColor);
if (theApp.GetNumberSetting(L"Options", L"Theme_UseDarkMode", false))
{
constexpr COLORREF darkBkColor = 0x383838;
constexpr COLORREF darkTextColor = 0xFFFFFF;
// Return a solid brush with the dark background color
static HBRUSH hbrBackground = CreateSolidBrush(RGB(45, 45, 45));
hbr = hbrBackground;
// If you need to customize specific controls, add conditions
switch (nCtlColor)
{
case CTLCOLOR_DLG: // Dialog background
case CTLCOLOR_STATIC: // Static text
case CTLCOLOR_EDIT: // Edit control
case CTLCOLOR_LISTBOX: // Listbox
pDC->SetTextColor(darkTextColor); // Light text
pDC->SetBkColor(darkBkColor); // Dark background
break;
break;
case CTLCOLOR_SCROLLBAR: // Scrollbars
case CTLCOLOR_BTN: // Buttons
default:
// You can add specific cases here if needed
break;
}
}
return hbr;
}
Share
Improve this question
edited Jan 22 at 17:51
Andrew Truckle
asked Jan 22 at 15:59
Andrew TruckleAndrew Truckle
19.2k17 gold badges84 silver badges218 bronze badges
1 Answer
Reset to default 1As far as I understand, Microsoft has implemented dark theme support only for the controls they use themselves in different parts of Windows. Therefore, I do not expect the dark theme to ever work natively for controls like the calendar or time picker. Our solution is to use Microsoft Detours to intercept APIs like GetThemeColor
and DrawThemeText
, substitute color, and call the original function. It works fine for example with checkbox and radio button controls, but we never implemented workarounds for other controls you might need. You can check our open-source project: https://github/SFTRS/DarkTaskDialog
本文标签: visual cUsing dark mode for Win32 statusbarStack Overflow
版权声明:本文标题:visual c++ - Using dark mode for Win32 statusbar - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742034997a2417179.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论