This commit is contained in:
恍兮惚兮 2024-05-29 09:37:43 +08:00
parent 5a719d16e5
commit ef5ebbd7fe
2 changed files with 17 additions and 25 deletions

View File

@ -2,7 +2,6 @@
#define DECLARE extern "C" __declspec(dllexport)
extern "C"
{
__declspec(dllexport) bool _SetTheme(HWND _hWnd, bool dark, int backdrop);
__declspec(dllexport) HANDLE startdarklistener();
__declspec(dllexport) bool queryversion(const wchar_t *exe, WORD *_1, WORD *_2, WORD *_3, WORD *_4);

View File

@ -1,14 +1,6 @@
#include "define.h"
// https://github.com/Blinue/Xaml-Islands-Cpp/blob/main/src/XamlIslandsCpp/XamlWindow.h
enum WindowBackdrop : int32_t
{
SolidColor = 0,
Acrylic = 1,
Mica = 2,
MicaAlt = 3,
};
static uint32_t GetOSBuild() noexcept
{
HMODULE hNtDll = GetModuleHandle(L"ntdll.dll");
@ -137,17 +129,17 @@ static void SetWindowTheme(HWND hWnd, bool darkBorder, bool darkMenu) noexcept
RefreshImmersiveColorPolicyState();
FlushMenuThemes();
}
bool _SetTheme(
DECLARE void _SetTheme(
HWND _hWnd,
bool dark,
int backdrop)
{
auto _isBackgroundSolidColor = backdrop == WindowBackdrop::SolidColor;
if (Win32Helper::GetOSVersion().Is22H2OrNewer() &&
_isBackgroundSolidColor != (backdrop == WindowBackdrop::SolidColor))
{
return true;
}
// auto _isBackgroundSolidColor = backdrop == WindowBackdrop::SolidColor;
// if (Win32Helper::GetOSVersion().Is22H2OrNewer() &&
// _isBackgroundSolidColor != (backdrop == WindowBackdrop::SolidColor))
// {
// return true;
// }
// Win10 中即使在亮色主题下我们也使用暗色边框,这也是 UWP 窗口的行为
SetWindowTheme(
@ -155,11 +147,12 @@ bool _SetTheme(
Win32Helper::GetOSVersion().IsWin11() ? dark : true,
dark);
if (!Win32Helper::GetOSVersion().Is22H2OrNewer())
{
return false;
}
// if (!Win32Helper::GetOSVersion().Is22H2OrNewer())
// {
// return false;
// }
// https://learn.microsoft.com/zh-cn/windows/win32/api/dwmapi/ne-dwmapi-dwm_systembackdrop_type
// 设置背景
static const DWM_SYSTEMBACKDROP_TYPE BACKDROP_MAP[] = {
DWMSBT_AUTO, DWMSBT_TRANSIENTWINDOW, DWMSBT_MAINWINDOW, DWMSBT_TABBEDWINDOW};
@ -170,7 +163,7 @@ bool _SetTheme(
DwmSetWindowAttribute(_hWnd, DWMWA_SYSTEMBACKDROP_TYPE, &value, sizeof(value));
return false;
}
DECLARE bool isDark()