diff --git a/LunaTranslator/LunaTranslator/winsharedutils.py b/LunaTranslator/LunaTranslator/winsharedutils.py index 1938ed17..99866a5e 100644 --- a/LunaTranslator/LunaTranslator/winsharedutils.py +++ b/LunaTranslator/LunaTranslator/winsharedutils.py @@ -316,10 +316,7 @@ _SetTheme.argtypes = HWND, c_bool, c_int def SetTheme(hwnd, dark, backdrop): - try: # win7 x86 crash unknown why - _SetTheme(hwnd, dark, backdrop) - except: - pass + _SetTheme(hwnd, dark, backdrop) showintab = utilsdll.showintab diff --git a/plugins/winsharedutils/theme.cpp b/plugins/winsharedutils/theme.cpp index 90fd6a0a..b422d0d1 100644 --- a/plugins/winsharedutils/theme.cpp +++ b/plugins/winsharedutils/theme.cpp @@ -1,6 +1,28 @@ #include "define.h" // https://github.com/Blinue/Xaml-Islands-Cpp/blob/main/src/XamlIslandsCpp/XamlWindow.h +static uint32_t GetOSversion() noexcept +{ + HMODULE hNtDll = GetModuleHandle(L"ntdll.dll"); + if (!hNtDll) + { + return 0; + } + + auto rtlGetVersion = (LONG(WINAPI *)(PRTL_OSVERSIONINFOW))GetProcAddress(hNtDll, "RtlGetVersion"); + if (rtlGetVersion == nullptr) + { + // assert(false); + return 0; + } + + RTL_OSVERSIONINFOW version{}; + version.dwOSVersionInfoSize = sizeof(version); + rtlGetVersion(&version); + + return version.dwMajorVersion; +} + static uint32_t GetOSBuild() noexcept { HMODULE hNtDll = GetModuleHandle(L"ntdll.dll"); @@ -22,7 +44,6 @@ static uint32_t GetOSBuild() noexcept return version.dwBuildNumber; } - struct Win32Helper { struct OSVersion @@ -134,6 +155,9 @@ DECLARE void _SetTheme( bool dark, int backdrop) { + // printf("%d %d\n",GetOSversion(),GetOSBuild()); + if (GetOSversion() <= 6)//win7 x32 DwmSetWindowAttribute会崩,直接禁了反正没用。不知道win8怎么样。 + return; // auto _isBackgroundSolidColor = backdrop == WindowBackdrop::SolidColor; // if (Win32Helper::GetOSVersion().Is22H2OrNewer() && // _isBackgroundSolidColor != (backdrop == WindowBackdrop::SolidColor))