diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/ExtendedWindow.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/ExtendedWindow.cs index 5b847406..3e842baa 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/ExtendedWindow.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/ExtendedWindow.cs @@ -11,8 +11,11 @@ using Snap.Hutao.Message; using Snap.Hutao.Service; using Snap.Hutao.Win32; using System.IO; +using Windows.Win32.Foundation; using Windows.Graphics; using Windows.UI; +using Windows.Win32.Graphics.Dwm; +using static Windows.Win32.PInvoke; namespace Snap.Hutao.Core.Windowing; @@ -65,22 +68,23 @@ internal sealed class ExtendedWindow : IRecipient(); UpdateSystemBackdrop(appOptions.BackdropType); appOptions.PropertyChanged += OnOptionsPropertyChanged; bool subClassApplied = subclass.Initialize(); - logger.LogInformation("Apply {name} : {result}", nameof(WindowSubclass), subClassApplied ? "succeed" : "failed"); - IMessenger messenger = serviceProvider.GetRequiredService(); - messenger.Register(this); + serviceProvider.GetRequiredService().Register(this); options.Window.Closed += OnWindowClosed; + options.TitleBar.ActualThemeChanged += UpdateImmersiveDarkMode; } private void OnOptionsPropertyChanged(object? sender, PropertyChangedEventArgs e) @@ -159,6 +163,12 @@ internal sealed class ExtendedWindow : IRecipient + /// 将窗口设为前台窗口 + /// + /// 窗口句柄 + public static unsafe void BringToForeground(in HWND hwnd) + { + HWND fgHwnd = GetForegroundWindow(); + + uint threadIdHwnd = GetWindowThreadProcessId(hwnd); + uint threadIdfgHwnd = GetWindowThreadProcessId(fgHwnd); + + if (threadIdHwnd != threadIdfgHwnd) + { + AttachThreadInput(threadIdHwnd, threadIdfgHwnd, true); + SetForegroundWindow(hwnd); + AttachThreadInput(threadIdHwnd, threadIdfgHwnd, false); + } + else + { + SetForegroundWindow(hwnd); + } + } + private static void TransformToCenterScreen(ref RectInt32 rect) { DisplayArea displayArea = DisplayArea.GetFromRect(rect, DisplayAreaFallback.Primary); diff --git a/src/Snap.Hutao/Snap.Hutao/NativeMethods.txt b/src/Snap.Hutao/Snap.Hutao/NativeMethods.txt index 16a0d474..29666b74 100644 --- a/src/Snap.Hutao/Snap.Hutao/NativeMethods.txt +++ b/src/Snap.Hutao/Snap.Hutao/NativeMethods.txt @@ -14,6 +14,10 @@ DefSubclassProc RemoveWindowSubclass SetWindowSubclass +// DWMAPI +DwmGetWindowAttribute +DwmSetWindowAttribute + // GDI32 GetDeviceCaps @@ -30,10 +34,14 @@ WriteProcessMemory CoWaitForMultipleObjects // USER32 +AttachThreadInput FindWindowEx GetDC GetDpiForWindow +GetForegroundWindow GetWindowPlacement +GetWindowThreadProcessId +SetForegroundWindow // WinRT IMemoryBufferByteAccess \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/View/Card/AchievementCard.xaml b/src/Snap.Hutao/Snap.Hutao/View/Card/AchievementCard.xaml index 906c87ae..8f396782 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Card/AchievementCard.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Card/AchievementCard.xaml @@ -52,7 +52,8 @@ Opacity="0.8" Style="{StaticResource SubtitleTextBlockStyle}" Text="{Binding Inner.Title}" - TextTrimming="CharacterEllipsis"/> + TextTrimming="CharacterEllipsis" + TextWrapping="NoWrap"/>