From 624af87795bd4806ca84f996308478d8cfc4189e Mon Sep 17 00:00:00 2001 From: CJKmkp <2564608840@qq.com> Date: Fri, 25 Jul 2025 18:12:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BE=A7=E8=BE=B9=E6=A0=8F=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=8F=8A=E6=B5=AE=E5=8A=A8=E6=A0=8F=E9=AB=98=E5=BA=A6?= =?UTF-8?q?=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/MainWindow.xaml.cs | 46 ++--------------------------------- 1 file changed, 2 insertions(+), 44 deletions(-) diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs index 23b5565d..a6979eb6 100644 --- a/Ink Canvas/MainWindow.xaml.cs +++ b/Ink Canvas/MainWindow.xaml.cs @@ -28,44 +28,7 @@ namespace Ink_Canvas { private System.Windows.Controls.Canvas currentCanvas = null; private AutoUpdateHelper.UpdateLineGroup AvailableLatestLineGroup = null; - // Win32 API声明和常量(用于无焦点窗口) - [DllImport("user32.dll")] - private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); - [DllImport("user32.dll")] - private static extern int GetWindowLong(IntPtr hWnd, int nIndex); - private const int GWL_EXSTYLE = -20; - private const int WS_EX_NOACTIVATE = 0x08000000; - [DllImport("user32.dll")] - private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); - private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1); - private static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2); - private const uint SWP_NOSIZE = 0x0001; - private const uint SWP_NOMOVE = 0x0002; - private const uint SWP_NOACTIVATE = 0x0010; - private const uint SWP_SHOWWINDOW = 0x0040; - - // 新增:设置窗口置顶并兼容无焦点 - private void SetTopmostWithNoActivate(bool topmost) - { - var hwnd = new WindowInteropHelper(this).Handle; - int exStyle = GetWindowLong(hwnd, GWL_EXSTYLE); - // 先移除 WS_EX_NOACTIVATE - SetWindowLong(hwnd, GWL_EXSTYLE, exStyle & ~WS_EX_NOACTIVATE); - // 设置 Topmost - this.Topmost = topmost; - // 使用SetWindowPos确保无焦点置顶 - if (topmost) - { - SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW); - } - else - { - SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW); - } - // 再加回 WS_EX_NOACTIVATE - exStyle = GetWindowLong(hwnd, GWL_EXSTYLE); - SetWindowLong(hwnd, GWL_EXSTYLE, exStyle | WS_EX_NOACTIVATE); - } + #region Window Initialization @@ -206,12 +169,7 @@ namespace Ink_Canvas { }; } - protected override void OnSourceInitialized(EventArgs e) - { - base.OnSourceInitialized(e); - // 设置窗口为无焦点且置顶(不会抢占焦点且始终在最前) - SetTopmostWithNoActivate(true); - } + #endregion