improve:点名UI
This commit is contained in:
@@ -1197,6 +1197,13 @@ namespace Ink_Canvas
|
|||||||
{
|
{
|
||||||
List<string> usedNames = new List<string>();
|
List<string> usedNames = new List<string>();
|
||||||
|
|
||||||
|
// 确保动画期间主显示区域可见
|
||||||
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
|
{
|
||||||
|
MainResultDisplay.Visibility = Visibility.Visible;
|
||||||
|
MultiResultScrollViewer.Visibility = Visibility.Collapsed;
|
||||||
|
});
|
||||||
|
|
||||||
for (int i = 0; i < animationTimes; i++)
|
for (int i = 0; i < animationTimes; i++)
|
||||||
{
|
{
|
||||||
// 随机选择一个名字进行动画显示
|
// 随机选择一个名字进行动画显示
|
||||||
@@ -1207,6 +1214,8 @@ namespace Ink_Canvas
|
|||||||
|
|
||||||
Application.Current.Dispatcher.Invoke(() =>
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
|
// 确保主显示区域在动画期间保持可见
|
||||||
|
MainResultDisplay.Visibility = Visibility.Visible;
|
||||||
MainResultDisplay.Text = displayName;
|
MainResultDisplay.Text = displayName;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1258,6 +1267,13 @@ namespace Ink_Canvas
|
|||||||
{
|
{
|
||||||
List<int> usedNumbers = new List<int>();
|
List<int> usedNumbers = new List<int>();
|
||||||
|
|
||||||
|
// 确保动画期间主显示区域可见
|
||||||
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
|
{
|
||||||
|
MainResultDisplay.Visibility = Visibility.Visible;
|
||||||
|
MultiResultScrollViewer.Visibility = Visibility.Collapsed;
|
||||||
|
});
|
||||||
|
|
||||||
for (int i = 0; i < animationTimes; i++)
|
for (int i = 0; i < animationTimes; i++)
|
||||||
{
|
{
|
||||||
// 随机选择一个数字进行动画显示
|
// 随机选择一个数字进行动画显示
|
||||||
@@ -1265,6 +1281,8 @@ namespace Ink_Canvas
|
|||||||
|
|
||||||
Application.Current.Dispatcher.Invoke(() =>
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
|
// 确保主显示区域在动画期间保持可见
|
||||||
|
MainResultDisplay.Visibility = Visibility.Visible;
|
||||||
MainResultDisplay.Text = randomNumber.ToString();
|
MainResultDisplay.Text = randomNumber.ToString();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1280,7 +1298,7 @@ namespace Ink_Canvas
|
|||||||
// 更新历史记录
|
// 更新历史记录
|
||||||
UpdateRollCallHistory(selectedNumbers);
|
UpdateRollCallHistory(selectedNumbers);
|
||||||
|
|
||||||
// 显示结果
|
// 显示结果(这里会根据结果数量决定显示主显示区域还是多结果区域)
|
||||||
ShowResults(selectedNumbers);
|
ShowResults(selectedNumbers);
|
||||||
UpdateStatusDisplay($"抽选完成,共选择 {selectedNumbers.Count} 个数字");
|
UpdateStatusDisplay($"抽选完成,共选择 {selectedNumbers.Count} 个数字");
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,13 @@ namespace Ink_Canvas
|
|||||||
|
|
||||||
// 应用置顶
|
// 应用置顶
|
||||||
ApplyFloatingButtonTopmost();
|
ApplyFloatingButtonTopmost();
|
||||||
|
|
||||||
|
// 如果主窗口在无焦点模式下,启动置顶维护
|
||||||
|
if (MainWindow.Settings?.Advanced?.IsNoFocusMode == true &&
|
||||||
|
MainWindow.Settings?.Advanced?.EnableUIAccessTopMost != true)
|
||||||
|
{
|
||||||
|
StartTopmostMaintenance();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetPositionToBottomRight()
|
private void SetPositionToBottomRight()
|
||||||
@@ -78,15 +85,39 @@ namespace Ink_Canvas
|
|||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
|
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern bool IsWindow(IntPtr hWnd);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
|
private static extern bool IsWindowVisible(IntPtr hWnd);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern bool IsIconic(IntPtr hWnd);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern IntPtr GetForegroundWindow();
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
|
||||||
|
|
||||||
|
[DllImport("kernel32.dll")]
|
||||||
|
private static extern uint GetCurrentProcessId();
|
||||||
|
|
||||||
private const int GWL_EXSTYLE = -20;
|
private const int GWL_EXSTYLE = -20;
|
||||||
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 const uint SWP_NOMOVE = 0x0002;
|
private const uint SWP_NOMOVE = 0x0002;
|
||||||
private const uint SWP_NOSIZE = 0x0001;
|
private const uint SWP_NOSIZE = 0x0001;
|
||||||
private const uint SWP_NOACTIVATE = 0x0010;
|
private const uint SWP_NOACTIVATE = 0x0010;
|
||||||
private const uint SWP_SHOWWINDOW = 0x0040;
|
private const uint SWP_SHOWWINDOW = 0x0040;
|
||||||
private const uint SWP_NOOWNERZORDER = 0x0200;
|
private const uint SWP_NOOWNERZORDER = 0x0200;
|
||||||
|
|
||||||
|
// 添加定时器来维护置顶状态
|
||||||
|
private DispatcherTimer topmostMaintenanceTimer;
|
||||||
|
private bool isTopmostMaintenanceEnabled;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 应用悬浮按钮置顶
|
/// 应用悬浮按钮置顶
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -96,11 +127,6 @@ namespace Ink_Canvas
|
|||||||
{
|
{
|
||||||
var hwnd = new WindowInteropHelper(this).Handle;
|
var hwnd = new WindowInteropHelper(this).Handle;
|
||||||
if (hwnd == IntPtr.Zero) return;
|
if (hwnd == IntPtr.Zero) return;
|
||||||
|
|
||||||
// 强制激活窗口
|
|
||||||
Activate();
|
|
||||||
Focus();
|
|
||||||
|
|
||||||
// 设置WPF的Topmost属性
|
// 设置WPF的Topmost属性
|
||||||
Topmost = true;
|
Topmost = true;
|
||||||
|
|
||||||
@@ -113,13 +139,116 @@ namespace Ink_Canvas
|
|||||||
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0,
|
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0,
|
||||||
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOOWNERZORDER);
|
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOOWNERZORDER);
|
||||||
|
|
||||||
LogHelper.WriteLogToFile("快抽悬浮按钮已应用置顶", LogHelper.LogType.Trace);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogHelper.WriteLogToFile($"应用快抽悬浮按钮置顶失败: {ex.Message}", LogHelper.LogType.Error);
|
LogHelper.WriteLogToFile($"应用快抽悬浮按钮置顶失败: {ex.Message}", LogHelper.LogType.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 启动置顶维护定时器
|
||||||
|
/// </summary>
|
||||||
|
private void StartTopmostMaintenance()
|
||||||
|
{
|
||||||
|
if (MainWindow.Settings?.Advanced?.EnableUIAccessTopMost == true)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isTopmostMaintenanceEnabled) return;
|
||||||
|
|
||||||
|
if (topmostMaintenanceTimer == null)
|
||||||
|
{
|
||||||
|
topmostMaintenanceTimer = new DispatcherTimer();
|
||||||
|
topmostMaintenanceTimer.Interval = TimeSpan.FromMilliseconds(500); // 每500ms检查一次
|
||||||
|
topmostMaintenanceTimer.Tick += TopmostMaintenanceTimer_Tick;
|
||||||
|
}
|
||||||
|
|
||||||
|
topmostMaintenanceTimer.Start();
|
||||||
|
isTopmostMaintenanceEnabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 停止置顶维护定时器
|
||||||
|
/// </summary>
|
||||||
|
private void StopTopmostMaintenance()
|
||||||
|
{
|
||||||
|
if (topmostMaintenanceTimer != null && isTopmostMaintenanceEnabled)
|
||||||
|
{
|
||||||
|
topmostMaintenanceTimer.Stop();
|
||||||
|
isTopmostMaintenanceEnabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 置顶维护定时器事件
|
||||||
|
/// </summary>
|
||||||
|
private void TopmostMaintenanceTimer_Tick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (MainWindow.Settings?.Advanced?.EnableUIAccessTopMost == true)
|
||||||
|
{
|
||||||
|
StopTopmostMaintenance();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MainWindow.Settings?.Advanced?.IsNoFocusMode != true)
|
||||||
|
{
|
||||||
|
StopTopmostMaintenance();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var hwnd = new WindowInteropHelper(this).Handle;
|
||||||
|
if (hwnd == IntPtr.Zero) return;
|
||||||
|
|
||||||
|
// 检查窗口是否仍然可见且不是最小化状态
|
||||||
|
if (!IsWindow(hwnd) || !IsWindowVisible(hwnd) || IsIconic(hwnd))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查是否有子窗口在前景
|
||||||
|
var foregroundWindow = GetForegroundWindow();
|
||||||
|
if (foregroundWindow != hwnd)
|
||||||
|
{
|
||||||
|
// 检查前景窗口是否是当前应用程序的子窗口
|
||||||
|
var foregroundWindowProcessId = GetWindowThreadProcessId(foregroundWindow, out uint processId);
|
||||||
|
var currentProcessId = GetCurrentProcessId();
|
||||||
|
|
||||||
|
if (processId == currentProcessId)
|
||||||
|
{
|
||||||
|
// 如果有子窗口在前景,暂停置顶维护
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果窗口不在最顶层且没有子窗口,重新设置置顶
|
||||||
|
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0,
|
||||||
|
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOOWNERZORDER);
|
||||||
|
|
||||||
|
// 确保窗口样式正确
|
||||||
|
int exStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
|
||||||
|
if ((exStyle & WS_EX_TOPMOST) == 0)
|
||||||
|
{
|
||||||
|
SetWindowLong(hwnd, GWL_EXSTYLE, exStyle | WS_EX_TOPMOST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LogHelper.WriteLogToFile($"快抽悬浮按钮置顶维护定时器出错: {ex.Message}", LogHelper.LogType.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 窗口关闭时停止置顶维护定时器
|
||||||
|
/// </summary>
|
||||||
|
protected override void OnClosed(EventArgs e)
|
||||||
|
{
|
||||||
|
StopTopmostMaintenance();
|
||||||
|
base.OnClosed(e);
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user