improve:快抽窗口
This commit is contained in:
@@ -25,6 +25,14 @@ namespace Ink_Canvas
|
|||||||
// 设置无焦点状态
|
// 设置无焦点状态
|
||||||
this.Focusable = false;
|
this.Focusable = false;
|
||||||
this.ShowInTaskbar = 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();
|
SetPositionToBottomRight();
|
||||||
|
|
||||||
|
// 应用无焦点模式
|
||||||
|
ApplyNoFocusMode();
|
||||||
|
|
||||||
// 应用置顶
|
// 应用置顶
|
||||||
ApplyFloatingButtonTopmost();
|
ApplyFloatingButtonTopmost();
|
||||||
|
|
||||||
// 如果主窗口在无焦点模式下,启动置顶维护
|
if (MainWindow.Settings?.Advanced?.EnableUIAccessTopMost != true)
|
||||||
if (MainWindow.Settings?.Advanced?.IsNoFocusMode == true &&
|
|
||||||
MainWindow.Settings?.Advanced?.EnableUIAccessTopMost != true)
|
|
||||||
{
|
{
|
||||||
StartTopmostMaintenance();
|
StartTopmostMaintenance();
|
||||||
}
|
}
|
||||||
@@ -174,6 +183,7 @@ namespace Ink_Canvas
|
|||||||
private static extern uint GetCurrentProcessId();
|
private static extern uint GetCurrentProcessId();
|
||||||
|
|
||||||
private const int GWL_EXSTYLE = -20;
|
private const int GWL_EXSTYLE = -20;
|
||||||
|
private const int WS_EX_NOACTIVATE = 0x08000000;
|
||||||
private const int WS_EX_TOPMOST = 0x00000008;
|
private const int WS_EX_TOPMOST = 0x00000008;
|
||||||
private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
|
private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
|
||||||
private static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
|
private static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
|
||||||
@@ -187,6 +197,26 @@ namespace Ink_Canvas
|
|||||||
private DispatcherTimer topmostMaintenanceTimer;
|
private DispatcherTimer topmostMaintenanceTimer;
|
||||||
private bool isTopmostMaintenanceEnabled;
|
private bool isTopmostMaintenanceEnabled;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 应用无焦点模式
|
||||||
|
/// </summary>
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 应用悬浮按钮置顶
|
/// 应用悬浮按钮置顶
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -263,11 +293,7 @@ namespace Ink_Canvas
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MainWindow.Settings?.Advanced?.IsNoFocusMode != true)
|
// 悬浮快抽窗口始终启用无焦点模式,不需要检查主窗口设置
|
||||||
{
|
|
||||||
StopTopmostMaintenance();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var hwnd = new WindowInteropHelper(this).Handle;
|
var hwnd = new WindowInteropHelper(this).Handle;
|
||||||
if (hwnd == IntPtr.Zero) return;
|
if (hwnd == IntPtr.Zero) return;
|
||||||
@@ -302,6 +328,12 @@ namespace Ink_Canvas
|
|||||||
{
|
{
|
||||||
SetWindowLong(hwnd, GWL_EXSTYLE, exStyle | WS_EX_TOPMOST);
|
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)
|
catch (Exception ex)
|
||||||
|
|||||||
Reference in New Issue
Block a user