1.1.3 -> 1.1.4 第14次更新

This commit is contained in:
Space Time 2024-11-25 16:29:58 +08:00
parent 48509f46cf
commit 144de24013
3 changed files with 45 additions and 15 deletions

View File

@ -1,7 +1,9 @@
using CommunityToolkit.Mvvm.ComponentModel; using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging; using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages; using CommunityToolkit.Mvvm.Messaging.Messages;
using MaterialDesignThemes.Wpf; using MaterialDesignThemes.Wpf;
using Sheas_Cealer.Utils;
namespace Sheas_Cealer.Preses; namespace Sheas_Cealer.Preses;
@ -18,6 +20,8 @@ internal partial class GlobalPres : ObservableRecipient, IRecipient<PropertyChan
newTheme.SetBaseTheme(value.HasValue ? value.GetValueOrDefault() ? BaseTheme.Light : BaseTheme.Dark : BaseTheme.Inherit); newTheme.SetBaseTheme(value.HasValue ? value.GetValueOrDefault() ? BaseTheme.Light : BaseTheme.Dark : BaseTheme.Inherit);
paletteHelper.SetTheme(newTheme); paletteHelper.SetTheme(newTheme);
BorderThemeSetter.SetBorderTheme(Application.Current.MainWindow, value);
} }
protected override void Broadcast<T>(T oldValue, T newValue, string? propertyName) => Messenger.Send(new PropertyChangedMessage<object>(this, propertyName, oldValue!, newValue!)); protected override void Broadcast<T>(T oldValue, T newValue, string? propertyName) => Messenger.Send(new PropertyChangedMessage<object>(this, propertyName, oldValue!, newValue!));

View File

@ -0,0 +1,31 @@
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
namespace Sheas_Cealer.Utils;
internal static partial class BorderThemeSetter
{
private const int DWMWA_USE_IMMERSIVE_DARK_MODE_OLD = 19;
private const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
[LibraryImport("dwmapi.dll")]
private static partial int DwmGetWindowAttribute(nint hwnd, uint attr, out nint attrValue, uint attrSize);
[LibraryImport("dwmapi.dll")]
private static partial int DwmSetWindowAttribute(nint hwnd, uint attr, ref nint attrValue, uint attrSize);
internal static void SetBorderTheme(Window window, bool? isLightTheme)
{
nint isDarkTheme;
nint desktopHwnd = nint.Zero;
nint windowHwnd = new WindowInteropHelper(window).EnsureHandle();
if (isLightTheme.HasValue)
isDarkTheme = !isLightTheme.Value ? 1 : 0;
else
DwmGetWindowAttribute(desktopHwnd, DWMWA_USE_IMMERSIVE_DARK_MODE, out isDarkTheme, (uint)Marshal.SizeOf(typeof(nint)));
_ = DwmSetWindowAttribute(windowHwnd, DWMWA_USE_IMMERSIVE_DARK_MODE_OLD, ref isDarkTheme, (uint)Marshal.SizeOf(typeof(nint)));
_ = DwmSetWindowAttribute(windowHwnd, DWMWA_USE_IMMERSIVE_DARK_MODE, ref isDarkTheme, (uint)Marshal.SizeOf(typeof(nint)));
}
}

View File

@ -1,5 +1,4 @@
using System; using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using System.Windows; using System.Windows;
using System.Windows.Interop; using System.Windows.Interop;
@ -16,28 +15,24 @@ internal static partial class IconRemover
private const uint WM_SETICON = 0x0080; private const uint WM_SETICON = 0x0080;
[LibraryImport("user32.dll", EntryPoint = "GetWindowLongW")] [LibraryImport("user32.dll", EntryPoint = "GetWindowLongW")]
private static partial int GetWindowLong(IntPtr hwnd, int index); private static partial int GetWindowLong(nint hwnd, int index);
[LibraryImport("user32.dll", EntryPoint = "SetWindowLongW")] [LibraryImport("user32.dll", EntryPoint = "SetWindowLongW")]
private static partial int SetWindowLong(IntPtr hwnd, int index, int newStyle); private static partial int SetWindowLong(nint hwnd, int index, nint newStyle);
[LibraryImport("user32.dll")] [LibraryImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
private static partial bool SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter, int x, int y, int width, int height, uint flags); private static partial bool SetWindowPos(nint hwnd, nint hwndInsertAfter, int x, int y, int width, int height, uint flags);
[LibraryImport("user32.dll", EntryPoint = "SendMessageW")] [LibraryImport("user32.dll", EntryPoint = "SendMessageW")]
private static partial IntPtr SendMessage(IntPtr hwnd, uint msg, IntPtr wParam, IntPtr lParam); private static partial nint SendMessage(nint hwnd, uint msg, nint wParam, nint lParam);
internal static void RemoveIcon(Window window) internal static void RemoveIcon(Window window)
{ {
// 获取该窗口句柄 nint hwnd = new WindowInteropHelper(window).Handle;
IntPtr hwnd = new WindowInteropHelper(window).Handle;
// 将窗口更改为不显示窗口图标
_ = SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_DLGMODALFRAME); _ = SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_DLGMODALFRAME);
// 更新窗口的非客户区域来显示更改 SetWindowPos(hwnd, nint.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
// 防止自定义图标生效 SendMessage(hwnd, WM_SETICON, new nint(1), nint.Zero);
SendMessage(hwnd, WM_SETICON, new IntPtr(1), IntPtr.Zero); SendMessage(hwnd, WM_SETICON, nint.Zero, nint.Zero);
SendMessage(hwnd, WM_SETICON, IntPtr.Zero, IntPtr.Zero);
} }
} }