The window title bar switches to dark when Windows is set to dark mode, and updates live when the setting is changed while the client is running.
Only one file to edit: EterLib/MSWindow.cpp
1. Search for:
Code:
CMSWindow::TWindowClassSet CMSWindow::ms_stWCSet;
HINSTANCE CMSWindow::ms_hInstance = NULL;
Code:
// Windows apps-theme setting; missing value (Wine, pre-1809) means light.
static bool IsSystemDarkMode()
{
DWORD value = 1;
DWORD size = sizeof(value);
if (::RegGetValueW(HKEY_CURRENT_USER,
L"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize",
L"AppsUseLightTheme", RRF_RT_REG_DWORD, nullptr, &value, &size) != ERROR_SUCCESS)
return false;
return value == 0;
}
// dwmapi is loaded dynamically: under Wine the call just fails and the
// Linux window manager keeps drawing the frame in the desktop theme.
static void ApplySystemTitleBarTheme(HWND hWnd)
{
using DwmSetWindowAttributeFn = HRESULT(WINAPI*)(HWND, DWORD, LPCVOID, DWORD);
constexpr DWORD UseImmersiveDarkMode = 20;
constexpr DWORD UseImmersiveDarkModeBefore20H1 = 19;
static HMODULE s_dwm = ::LoadLibraryA("dwmapi.dll");
if (!s_dwm)
return;
static auto s_setAttr =
reinterpret_cast<DwmSetWindowAttributeFn>(
::GetProcAddress(s_dwm, "DwmSetWindowAttribute"));
if (!s_setAttr)
return;
BOOL dark = IsSystemDarkMode() ? TRUE : FALSE;
if (FAILED(s_setAttr(hWnd, UseImmersiveDarkMode, &dark, sizeof(dark))))
s_setAttr(hWnd, UseImmersiveDarkModeBefore20H1, &dark, sizeof(dark));
}
2. Search for:
Code:
case WM_ACTIVATEAPP:
m_isActive = (wParam == WA_ACTIVE) || (wParam == WA_CLICKACTIVE);
break;
Code:
// Sent when the user toggles light/dark mode while the client runs.
case WM_SETTINGCHANGE:
if (lParam && ::lstrcmpiW((LPCWSTR)lParam, L"ImmersiveColorSet") == 0)
{
ApplySystemTitleBarTheme(hWnd);
::SetWindowPos(hWnd, nullptr, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
}
break;
3. Search for (inside CMSWindow::Create):
Code:
SetWindowLongPtrW(m_hWnd, GWLP_USERDATA, (LONG_PTR)this);
Code:
ApplySystemTitleBarTheme(m_hWnd);

