diff --git a/Ink Canvas/Windows/RandWindow.xaml.cs b/Ink Canvas/Windows/RandWindow.xaml.cs
index aa391d8f..c80ed0a4 100644
--- a/Ink Canvas/Windows/RandWindow.xaml.cs
+++ b/Ink Canvas/Windows/RandWindow.xaml.cs
@@ -6,11 +6,14 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
+using System.Runtime.InteropServices;
using System.Threading;
using System.Windows;
using System.Windows.Input;
+using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
+using System.Windows.Threading;
using MessageBox = iNKORE.UI.WPF.Modern.Controls.MessageBox;
namespace Ink_Canvas
@@ -30,6 +33,15 @@ namespace Ink_Canvas
// 加载背景
LoadBackground(settings);
+
+ // 设置窗口为置顶
+ Topmost = true;
+
+ // 添加窗口关闭事件处理
+ Closed += RandWindow_Closed;
+
+ // 添加窗口显示事件处理,确保置顶
+ Loaded += RandWindow_Loaded;
}
private void LoadBackground(Settings settings)
@@ -76,6 +88,15 @@ namespace Ink_Canvas
// 加载背景
LoadBackground(settings);
+ // 设置窗口为置顶
+ Topmost = true;
+
+ // 添加窗口关闭事件处理
+ Closed += RandWindow_Closed;
+
+ // 添加窗口显示事件处理,确保置顶
+ Loaded += RandWindow_Loaded;
+
new Thread(() =>
{
Thread.Sleep(100);
@@ -100,7 +121,7 @@ namespace Ink_Canvas
if (RandMaxPeopleOneTime != -1 && TotalCount >= RandMaxPeopleOneTime) return;
TotalCount++;
LabelNumberCount.Text = TotalCount.ToString();
- SymbolIconStart.Symbol = Symbol.People;
+ SymbolIconStart.Symbol = iNKORE.UI.WPF.Modern.Controls.Symbol.People;
BorderBtnAdd.Opacity = 1;
BorderBtnMinus.Opacity = 1;
}
@@ -112,7 +133,7 @@ namespace Ink_Canvas
LabelNumberCount.Text = TotalCount.ToString();
if (TotalCount == 1)
{
- SymbolIconStart.Symbol = Symbol.Contact;
+ SymbolIconStart.Symbol = iNKORE.UI.WPF.Modern.Controls.Symbol.Contact;
}
}
@@ -337,5 +358,70 @@ namespace Ink_Canvas
MessageBox.Show("无法调用外部点名:" + ex.Message);
}
}
+
+ ///
+ /// 窗口加载事件处理
+ ///
+ private void RandWindow_Loaded(object sender, RoutedEventArgs e)
+ {
+ // 使用延迟确保窗口完全加载后再应用置顶
+ Dispatcher.BeginInvoke(new Action(() =>
+ {
+ try
+ {
+ // 强制激活窗口
+ Activate();
+ Focus();
+
+ // 设置置顶
+ Topmost = true;
+
+ // 使用Win32 API强制置顶
+ var hwnd = new WindowInteropHelper(this).Handle;
+ if (hwnd != IntPtr.Zero)
+ {
+ const int WS_EX_TOPMOST = 0x00000008;
+ const int GWL_EXSTYLE = -20;
+ const int SWP_NOMOVE = 0x0002;
+ const int SWP_NOSIZE = 0x0001;
+ const int SWP_SHOWWINDOW = 0x0040;
+ const int SWP_NOOWNERZORDER = 0x0200;
+ var HWND_TOPMOST = new IntPtr(-1);
+
+ // 设置窗口样式为置顶
+ int exStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
+ SetWindowLong(hwnd, GWL_EXSTYLE, exStyle | WS_EX_TOPMOST);
+
+ // 强制置顶
+ SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0,
+ SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOOWNERZORDER);
+ }
+ }
+ catch (Exception ex)
+ {
+ LogHelper.WriteLogToFile($"RandWindow置顶失败: {ex.Message}", LogHelper.LogType.Error);
+ }
+ }), DispatcherPriority.Loaded);
+ }
+
+ ///
+ /// 窗口关闭事件处理
+ ///
+ private void RandWindow_Closed(object sender, EventArgs e)
+ {
+ // 窗口关闭时的清理工作
+ // 这里可以添加必要的清理代码
+ }
+
+ #region Win32 API 声明
+ [DllImport("user32.dll")]
+ private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
+
+ [DllImport("user32.dll")]
+ private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
+
+ [DllImport("user32.dll")]
+ private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
+ #endregion
}
}