diff --git a/src/common/settcmn.cpp b/src/common/settcmn.cpp index f83e68786c..0a80c6fac3 100644 --- a/src/common/settcmn.cpp +++ b/src/common/settcmn.cpp @@ -75,12 +75,17 @@ wxString wxSystemAppearance::GetName() const return wxString(); } +#endif // !__WXOSX__ + +// These ports implement this function using platform-specific API. +#if !defined(__WXOSX__) && !defined(__WXMSW__) + bool wxSystemAppearance::IsDark() const { return IsUsingDarkBackground(); } -#endif // !__WXOSX__ +#endif // !__WXOSX__ && !__WXMSW__ bool wxSystemAppearance::IsUsingDarkBackground() const { diff --git a/src/msw/settings.cpp b/src/msw/settings.cpp index f4b33df25a..5ffc629c00 100644 --- a/src/msw/settings.cpp +++ b/src/msw/settings.cpp @@ -32,6 +32,7 @@ #include "wx/msw/private.h" #include "wx/msw/missing.h" // for SM_CXCURSOR, SM_CYCURSOR, SM_TABLETPC #include "wx/msw/private/metrics.h" +#include "wx/msw/registry.h" #include "wx/fontutil.h" #include "wx/fontenum.h" @@ -359,3 +360,24 @@ extern wxFont wxGetCCDefaultFont() } #endif // wxUSE_LISTCTRL || wxUSE_TREECTRL + +// There is no official API for determining whether dark mode is being used, +// but // HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize has +// a value AppsUseLightTheme = 0 for dark mode and 1 for normal mode, so use it +// and fall back to the generic algorithm in IsUsingDarkBackground() if it's +// absent. +// +// Adapted from https://stackoverflow.com/a/51336913/15275 ("How to detect +// Windows 10 light/dark mode in Win32 application?"). +bool wxSystemAppearance::IsDark() const +{ + wxRegKey rk(wxRegKey::HKCU, "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"); + if ( rk.Exists() && rk.HasValue("AppsUseLightTheme") ) + { + long value = -1; + if ( rk.QueryValue("AppsUseLightTheme", &value) ) + return value <= 0; + } + + return IsUsingDarkBackground(); +}