diff --git a/Ink Canvas/Windows/QuickDrawFloatingButton.cs b/Ink Canvas/Windows/QuickDrawFloatingButton.cs index 61aebc2f..062306bf 100644 --- a/Ink Canvas/Windows/QuickDrawFloatingButton.cs +++ b/Ink Canvas/Windows/QuickDrawFloatingButton.cs @@ -25,6 +25,14 @@ namespace Ink_Canvas // 设置无焦点状态 this.Focusable = false; this.ShowInTaskbar = false; + + // 窗口句柄创建后应用无焦点模式 + this.SourceInitialized += QuickDrawFloatingButton_SourceInitialized; + } + + private void QuickDrawFloatingButton_SourceInitialized(object sender, EventArgs e) + { + ApplyNoFocusMode(); } @@ -33,12 +41,13 @@ namespace Ink_Canvas // 设置位置到屏幕右下角稍微靠近中部 SetPositionToBottomRight(); + // 应用无焦点模式 + ApplyNoFocusMode(); + // 应用置顶 ApplyFloatingButtonTopmost(); - // 如果主窗口在无焦点模式下,启动置顶维护 - if (MainWindow.Settings?.Advanced?.IsNoFocusMode == true && - MainWindow.Settings?.Advanced?.EnableUIAccessTopMost != true) + if (MainWindow.Settings?.Advanced?.EnableUIAccessTopMost != true) { StartTopmostMaintenance(); } @@ -174,6 +183,7 @@ namespace Ink_Canvas private static extern uint GetCurrentProcessId(); private const int GWL_EXSTYLE = -20; + private const int WS_EX_NOACTIVATE = 0x08000000; private const int WS_EX_TOPMOST = 0x00000008; private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1); private static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2); @@ -187,6 +197,26 @@ namespace Ink_Canvas private DispatcherTimer topmostMaintenanceTimer; private bool isTopmostMaintenanceEnabled; + /// + /// 应用无焦点模式 + /// + private void ApplyNoFocusMode() + { + try + { + var hwnd = new WindowInteropHelper(this).Handle; + if (hwnd == IntPtr.Zero) return; + + int exStyle = GetWindowLong(hwnd, GWL_EXSTYLE); + + // 悬浮快抽窗口始终启用无焦点模式 + SetWindowLong(hwnd, GWL_EXSTYLE, exStyle | WS_EX_NOACTIVATE); + } + catch (Exception) + { + } + } + /// /// 应用悬浮按钮置顶 /// @@ -263,11 +293,7 @@ namespace Ink_Canvas return; } - if (MainWindow.Settings?.Advanced?.IsNoFocusMode != true) - { - StopTopmostMaintenance(); - return; - } + // 悬浮快抽窗口始终启用无焦点模式,不需要检查主窗口设置 var hwnd = new WindowInteropHelper(this).Handle; if (hwnd == IntPtr.Zero) return; @@ -302,6 +328,12 @@ namespace Ink_Canvas { SetWindowLong(hwnd, GWL_EXSTYLE, exStyle | WS_EX_TOPMOST); } + + // 确保无焦点模式样式正确 + if ((exStyle & WS_EX_NOACTIVATE) == 0) + { + SetWindowLong(hwnd, GWL_EXSTYLE, exStyle | WS_EX_NOACTIVATE); + } } } catch (Exception ex)