From ba6303dca0946c1dbc2635ff5e6534b62cb5e10d Mon Sep 17 00:00:00 2001 From: unknown <2564608840@qq.com> Date: Sun, 20 Jul 2025 21:01:15 +0800 Subject: [PATCH] =?UTF-8?q?improve:=E7=AA=97=E5=8F=A3=E6=97=A0=E7=84=A6?= =?UTF-8?q?=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/MainWindow.xaml.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs index ec53312a..7171b72f 100644 --- a/Ink Canvas/MainWindow.xaml.cs +++ b/Ink Canvas/MainWindow.xaml.cs @@ -34,6 +34,14 @@ 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; + #region Window Initialization public MainWindow() { @@ -310,6 +318,11 @@ namespace Ink_Canvas { // 初始化插件系统 InitializePluginSystem(); + + // 设置窗口为无焦点(不会抢占焦点) + var hwnd = new WindowInteropHelper(this).Handle; + int exStyle = GetWindowLong(hwnd, GWL_EXSTYLE); + SetWindowLong(hwnd, GWL_EXSTYLE, exStyle | WS_EX_NOACTIVATE); } private void SystemEventsOnDisplaySettingsChanged(object sender, EventArgs e) {