From 231b850f747e5918277e8a425cfbea174cbc1e58 Mon Sep 17 00:00:00 2001 From: PrefacedCorg <1876568293@qq.com> Date: Fri, 17 Apr 2026 13:14:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E7=AA=97=E5=8F=A3=E7=BD=AE=E9=A1=B6?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/MainWindow.xaml.cs | 3 + .../MainWindow_cs/MW_FloatingBarIcons.cs | 20 +++-- Ink Canvas/MainWindow_cs/MW_PPT.cs | 42 ++++++++-- Ink Canvas/Windows/RandWindow.xaml.cs | 4 +- .../Windows/YesOrNoNotificationWindow.xaml.cs | 78 ++++++++++++++++++- 5 files changed, 134 insertions(+), 13 deletions(-) diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs index fcc309a3..00d7e870 100644 --- a/Ink Canvas/MainWindow.xaml.cs +++ b/Ink Canvas/MainWindow.xaml.cs @@ -2896,6 +2896,7 @@ namespace Ink_Canvas BorderSettings.Visibility = Visibility.Hidden; BorderSettingsMask.Visibility = Visibility.Hidden; var win = new HistoryRollbackWindow(Settings.Startup.UpdateChannel); + win.Owner = this; win.ShowDialog(); // 可选:回滚窗口关闭后恢复设置面板显示 BorderSettings.Visibility = Visibility.Visible; @@ -3349,6 +3350,7 @@ namespace Ink_Canvas // 创建快捷键设置窗口 var hotkeySettingsWindow = new HotkeySettingsWindow(this, _globalHotkeyManager); + hotkeySettingsWindow.Owner = this; // 设置窗口关闭事件,用于在快捷键设置窗口关闭后恢复设置面板 hotkeySettingsWindow.Closed += (s, e) => @@ -4692,6 +4694,7 @@ namespace Ink_Canvas return; var quickDrawWindow = new QuickDrawWindow(); + quickDrawWindow.Owner = this; quickDrawWindow.ShowDialog(); } catch (Exception ex) diff --git a/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs b/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs index e51bcfb7..6c7c049f 100644 --- a/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs +++ b/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs @@ -1215,7 +1215,9 @@ namespace Ink_Canvas if (Settings.RandSettings.UseNewRollCallUI) { // 使用新点名UI - 随机抽模式 - new NewStyleRollCallWindow(Settings, false).ShowDialog(); + var rollCallWindow = new NewStyleRollCallWindow(Settings, false); + rollCallWindow.Owner = this; + rollCallWindow.ShowDialog(); } else { @@ -1378,11 +1380,15 @@ namespace Ink_Canvas // 调用失败时回退到相应的点名窗口 if (Settings.RandSettings.UseNewRollCallUI) { - new NewStyleRollCallWindow(Settings, true).ShowDialog(); // 单次抽模式 + var rollCallWindow = new NewStyleRollCallWindow(Settings, true); // 单次抽模式 + rollCallWindow.Owner = this; + rollCallWindow.ShowDialog(); } else { - new RandWindow(Settings, true).ShowDialog(); + var randWindow = new RandWindow(Settings, true); + randWindow.Owner = this; + randWindow.ShowDialog(); } } } @@ -1392,12 +1398,16 @@ namespace Ink_Canvas if (Settings.RandSettings.UseNewRollCallUI) { // 使用新点名UI - 单次抽模式 - new NewStyleRollCallWindow(Settings, true).ShowDialog(); + var rollCallWindow = new NewStyleRollCallWindow(Settings, true); + rollCallWindow.Owner = this; + rollCallWindow.ShowDialog(); } else { // 使用默认的随机点名窗口 - new RandWindow(Settings, true).ShowDialog(); + var randWindow = new RandWindow(Settings, true); + randWindow.Owner = this; + randWindow.ShowDialog(); } } } diff --git a/Ink Canvas/MainWindow_cs/MW_PPT.cs b/Ink Canvas/MainWindow_cs/MW_PPT.cs index e9fd850f..1437027e 100644 --- a/Ink Canvas/MainWindow_cs/MW_PPT.cs +++ b/Ink Canvas/MainWindow_cs/MW_PPT.cs @@ -1652,7 +1652,7 @@ namespace Ink_Canvas if (int.TryParse(File.ReadAllText(positionFile), out var page) && page > 0) { _lastPlaybackPage = page; - new YesOrNoNotificationWindow($"上次播放到了第 {page} 页, 是否立即跳转", () => + var yesNoWindow = new YesOrNoNotificationWindow($"上次播放到了第 {page} 页, 是否立即跳转", () => { try { @@ -1674,7 +1674,17 @@ namespace Ink_Canvas { LogHelper.WriteLogToFile($"跳转到第{page}页失败: {ex}", LogHelper.LogType.Error); } - }).ShowDialog(); + }); + yesNoWindow.Owner = this; + PauseTopmostMaintenance(); + try + { + yesNoWindow.ShowDialog(); + } + finally + { + ResumeTopmostMaintenance(); + } } } catch (Exception ex) @@ -1716,7 +1726,7 @@ namespace Ink_Canvas if (hasHiddenSlides && !IsShowingRestoreHiddenSlidesWindow) { IsShowingRestoreHiddenSlidesWindow = true; - new YesOrNoNotificationWindow("检测到此演示文档中包含隐藏的幻灯片,是否取消隐藏?", + var yesNoWindow = new YesOrNoNotificationWindow("检测到此演示文档中包含隐藏的幻灯片,是否取消隐藏?", () => { try @@ -1740,7 +1750,17 @@ namespace Ink_Canvas } }, () => { IsShowingRestoreHiddenSlidesWindow = false; }, - () => { IsShowingRestoreHiddenSlidesWindow = false; }).ShowDialog(); + () => { IsShowingRestoreHiddenSlidesWindow = false; }); + yesNoWindow.Owner = this; + PauseTopmostMaintenance(); + try + { + yesNoWindow.ShowDialog(); + } + finally + { + ResumeTopmostMaintenance(); + } } } catch (Exception ex) @@ -1786,7 +1806,7 @@ namespace Ink_Canvas if (hasSlideTimings && !IsShowingAutoplaySlidesWindow) { IsShowingAutoplaySlidesWindow = true; - new YesOrNoNotificationWindow("检测到此演示文档中自动播放或排练计时已经启用,可能导致幻灯片自动翻页,是否取消?", + var yesNoWindow = new YesOrNoNotificationWindow("检测到此演示文档中自动播放或排练计时已经启用,可能导致幻灯片自动翻页,是否取消?", () => { try @@ -1806,7 +1826,17 @@ namespace Ink_Canvas } }, () => { IsShowingAutoplaySlidesWindow = false; }, - () => { IsShowingAutoplaySlidesWindow = false; }).ShowDialog(); + () => { IsShowingAutoplaySlidesWindow = false; }); + yesNoWindow.Owner = this; + PauseTopmostMaintenance(); + try + { + yesNoWindow.ShowDialog(); + } + finally + { + ResumeTopmostMaintenance(); + } } } catch (Exception ex) diff --git a/Ink Canvas/Windows/RandWindow.xaml.cs b/Ink Canvas/Windows/RandWindow.xaml.cs index b49540fc..faa9a39f 100644 --- a/Ink Canvas/Windows/RandWindow.xaml.cs +++ b/Ink Canvas/Windows/RandWindow.xaml.cs @@ -401,7 +401,9 @@ namespace Ink_Canvas if (!ok) return; } - new NamesInputWindow().ShowDialog(); + var namesInputWindow = new NamesInputWindow(); + namesInputWindow.Owner = this; + namesInputWindow.ShowDialog(); Window_Loaded(this, null); } diff --git a/Ink Canvas/Windows/YesOrNoNotificationWindow.xaml.cs b/Ink Canvas/Windows/YesOrNoNotificationWindow.xaml.cs index 241884b9..533ec9d9 100644 --- a/Ink Canvas/Windows/YesOrNoNotificationWindow.xaml.cs +++ b/Ink Canvas/Windows/YesOrNoNotificationWindow.xaml.cs @@ -1,5 +1,8 @@ -using System; +using System; +using System.Runtime.InteropServices; using System.Windows; +using System.Windows.Interop; +using System.Windows.Threading; namespace Ink_Canvas { @@ -8,9 +11,26 @@ namespace Ink_Canvas /// public partial class YesOrNoNotificationWindow : Window { + [DllImport("user32.dll")] + private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); + + [DllImport("user32.dll")] + private static extern IntPtr GetForegroundWindow(); + + [DllImport("user32.dll")] + private static extern bool IsWindowVisible(IntPtr hWnd); + + private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1); + private const uint SWP_NOMOVE = 0x0002; + private const uint SWP_NOSIZE = 0x0001; + private const uint SWP_SHOWWINDOW = 0x0040; + private const uint SWP_NOOWNERZORDER = 0x0200; + private readonly Action _yesAction; private readonly Action _noAction; private readonly Action _windowClose; + private DispatcherTimer _topmostCheckTimer; + private IntPtr _hwnd; public YesOrNoNotificationWindow(string text, Action yesAction = null, Action noAction = null, Action windowClose = null) { @@ -19,6 +39,62 @@ namespace Ink_Canvas _windowClose = windowClose; InitializeComponent(); Label.Text = text; + + Loaded += YesOrNoNotificationWindow_Loaded; + Closed += YesOrNoNotificationWindow_Closed; + } + + private void YesOrNoNotificationWindow_Loaded(object sender, RoutedEventArgs e) + { + _hwnd = new WindowInteropHelper(this).Handle; + + Topmost = true; + Activate(); + Focus(); + + if (_hwnd != IntPtr.Zero) + { + SetWindowPos(_hwnd, HWND_TOPMOST, 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOOWNERZORDER); + } + + _topmostCheckTimer = new DispatcherTimer(); + _topmostCheckTimer.Interval = TimeSpan.FromMilliseconds(100); + _topmostCheckTimer.Tick += TopmostCheckTimer_Tick; + _topmostCheckTimer.Start(); + } + + private void TopmostCheckTimer_Tick(object sender, EventArgs e) + { + try + { + if (_hwnd == IntPtr.Zero) return; + + var foregroundWindow = GetForegroundWindow(); + + if (foregroundWindow != _hwnd && IsWindowVisible(_hwnd)) + { + Topmost = true; + Activate(); + Focus(); + + SetWindowPos(_hwnd, HWND_TOPMOST, 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOOWNERZORDER); + } + } + catch (Exception) + { + } + } + + private void YesOrNoNotificationWindow_Closed(object sender, EventArgs e) + { + if (_topmostCheckTimer != null) + { + _topmostCheckTimer.Stop(); + _topmostCheckTimer.Tick -= TopmostCheckTimer_Tick; + _topmostCheckTimer = null; + } } private void ButtonYes_Click(object sender, RoutedEventArgs e)