From 979be117c6b3d5451fd566ad55717ec300d96809 Mon Sep 17 00:00:00 2001
From: CJKmkp <2564608840@qq.com>
Date: Sat, 13 Sep 2025 16:02:39 +0800
Subject: [PATCH] add:issue #180
---
.../FloatingWindowInterceptorManager.cs | 25 ----
.../Helpers/FloatingWindowInterceptor.cs | 17 +--
Ink Canvas/MainWindow.xaml | 20 ---
.../MW_FloatingWindowInterceptor.cs | 137 ++----------------
4 files changed, 15 insertions(+), 184 deletions(-)
diff --git a/Ink Canvas/FloatingWindowInterceptorManager.cs b/Ink Canvas/FloatingWindowInterceptorManager.cs
index 3618f09f..ea4ecf69 100644
--- a/Ink Canvas/FloatingWindowInterceptorManager.cs
+++ b/Ink Canvas/FloatingWindowInterceptorManager.cs
@@ -164,31 +164,6 @@ namespace Ink_Canvas
}
}
- ///
- /// 调试:列出所有可见窗口
- ///
- public void DebugListAllWindows()
- {
- if (_interceptor == null)
- {
- LogHelper.WriteLogToFile("拦截器未初始化,无法进行调试", LogHelper.LogType.Warning);
- return;
- }
-
- try
- {
- LogHelper.WriteLogToFile("开始调试扫描所有可见窗口...", LogHelper.LogType.Event);
-
- // 直接调用扫描方法,在扫描过程中会输出调试信息
- _interceptor.ScanOnce();
-
- LogHelper.WriteLogToFile("调试扫描完成,请查看日志文件获取详细信息", LogHelper.LogType.Event);
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogToFile($"调试列出窗口失败: {ex.Message}", LogHelper.LogType.Error);
- }
- }
///
/// 恢复所有被拦截的窗口
diff --git a/Ink Canvas/Helpers/FloatingWindowInterceptor.cs b/Ink Canvas/Helpers/FloatingWindowInterceptor.cs
index eedd031a..fd931027 100644
--- a/Ink Canvas/Helpers/FloatingWindowInterceptor.cs
+++ b/Ink Canvas/Helpers/FloatingWindowInterceptor.cs
@@ -212,8 +212,8 @@ namespace Ink_Canvas.Helpers
{
Type = InterceptType.SeewoWhiteboard5Floating,
ProcessName = "EasiNote5",
- WindowTitlePattern = "",
- ClassNamePattern = "",
+ WindowTitlePattern = "希沃白板",
+ ClassNamePattern = "EasiNote5",
IsEnabled = true,
RequiresAdmin = false,
Description = "希沃白板5 桌面悬浮窗"
@@ -351,7 +351,7 @@ namespace Ink_Canvas.Helpers
Description = "希沃桌面 侧栏悬浮窗"
};
- // 测试规则 - 拦截所有小窗口
+ // 拦截所有小窗口
_interceptRules[InterceptType.SeewoWhiteboard3Floating] = new InterceptRule
{
Type = InterceptType.SeewoWhiteboard3Floating,
@@ -360,7 +360,7 @@ namespace Ink_Canvas.Helpers
ClassNamePattern = "",
IsEnabled = false, // 默认关闭,需要手动开启
RequiresAdmin = false,
- Description = "测试规则 - 拦截所有小窗口"
+ Description = "拦截所有小窗口"
};
}
@@ -495,9 +495,6 @@ namespace Ink_Canvas.Helpers
var windowInfo = GetWindowInfo(hWnd);
if (windowInfo == null) return true;
- // 输出调试信息到日志
- LogHelper.WriteLogToFile($"检测到窗口: '{windowInfo.WindowTitle}' | 进程: '{windowInfo.ProcessName}' | 类名: '{windowInfo.ClassName}'", LogHelper.LogType.Event);
-
// 检查窗口样式,过滤掉系统窗口和主窗口
var exStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
var style = GetWindowLong(hWnd, -16); // GWL_STYLE
@@ -505,7 +502,6 @@ namespace Ink_Canvas.Helpers
// 跳过工具窗口
if ((exStyle & WS_EX_TOOLWINDOW) != 0)
{
- LogHelper.WriteLogToFile($"跳过工具窗口: {windowInfo.WindowTitle}", LogHelper.LogType.Event);
return true;
}
@@ -514,7 +510,6 @@ namespace Ink_Canvas.Helpers
const uint WS_SYSMENU = 0x00080000;
if ((style & WS_CAPTION) != 0 && (style & WS_SYSMENU) != 0)
{
- LogHelper.WriteLogToFile($"跳过主窗口: {windowInfo.WindowTitle}", LogHelper.LogType.Event);
return true;
}
@@ -526,7 +521,6 @@ namespace Ink_Canvas.Helpers
if (width > 600 || height > 400)
{
- LogHelper.WriteLogToFile($"跳过大窗口 ({width}x{height}): {windowInfo.WindowTitle}", LogHelper.LogType.Event);
return true;
}
@@ -537,7 +531,6 @@ namespace Ink_Canvas.Helpers
if (MatchesRule(windowInfo, rule))
{
- LogHelper.WriteLogToFile($"匹配规则 '{rule.Description}',开始拦截窗口: {windowInfo.WindowTitle}", LogHelper.LogType.Event);
InterceptWindow(hWnd, rule);
break;
}
@@ -647,8 +640,6 @@ namespace Ink_Canvas.Helpers
// 记录拦截的窗口
_interceptedWindows[hWnd] = rule.Type;
- LogHelper.WriteLogToFile($"成功拦截窗口: {GetWindowTitle(hWnd)}", LogHelper.LogType.Event);
-
// 触发事件
WindowIntercepted?.Invoke(this, new WindowInterceptedEventArgs
{
diff --git a/Ink Canvas/MainWindow.xaml b/Ink Canvas/MainWindow.xaml
index a0b6dedf..6af5fac6 100644
--- a/Ink Canvas/MainWindow.xaml
+++ b/Ink Canvas/MainWindow.xaml
@@ -2964,30 +2964,10 @@
-
-
-
-
-
diff --git a/Ink Canvas/MainWindow_cs/MW_FloatingWindowInterceptor.cs b/Ink Canvas/MainWindow_cs/MW_FloatingWindowInterceptor.cs
index 93b9b550..ea78e7cb 100644
--- a/Ink Canvas/MainWindow_cs/MW_FloatingWindowInterceptor.cs
+++ b/Ink Canvas/MainWindow_cs/MW_FloatingWindowInterceptor.cs
@@ -1,6 +1,7 @@
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern.Controls;
using System;
+using System.Linq;
using System.Windows;
using System.Windows.Controls;
@@ -79,17 +80,21 @@ namespace Ink_Canvas
var isEnabled = Settings.Automation.FloatingWindowInterceptor.IsEnabled;
FloatingWindowInterceptorGrid.Visibility = isEnabled ? Visibility.Visible : Visibility.Collapsed;
+ // 计算启用的规则数量
+ var enabledRulesCount = Settings.Automation.FloatingWindowInterceptor.InterceptRules.Where(kvp => kvp.Value).Count();
+ var totalRulesCount = Settings.Automation.FloatingWindowInterceptor.InterceptRules.Count;
+
// 更新状态文本
if (_floatingWindowInterceptorManager != null)
{
var stats = _floatingWindowInterceptorManager.GetStatistics();
TextBlockFloatingWindowInterceptorStatus.Text = stats.IsRunning
- ? $"拦截器运行中 - 已启用 {stats.EnabledRules}/{stats.TotalRules} 个规则"
- : "拦截器未启动";
+ ? $"拦截器运行中 - 已启用 {enabledRulesCount}/{totalRulesCount} 个规则"
+ : $"拦截器未启动 - 已启用 {enabledRulesCount}/{totalRulesCount} 个规则";
}
else
{
- TextBlockFloatingWindowInterceptorStatus.Text = "拦截器未初始化";
+ TextBlockFloatingWindowInterceptorStatus.Text = $"拦截器未初始化 - 已启用 {enabledRulesCount}/{totalRulesCount} 个规则";
}
}
catch (Exception ex)
@@ -308,6 +313,9 @@ namespace Ink_Canvas
Settings.Automation.FloatingWindowInterceptor.InterceptRules[ruleName] = enabled;
}
+ // 更新UI显示
+ UpdateFloatingWindowInterceptorUI();
+
SaveSettingsToFile();
}
catch (Exception ex)
@@ -316,62 +324,6 @@ namespace Ink_Canvas
}
}
- ///
- /// 启动拦截按钮点击
- ///
- private void BtnFloatingWindowInterceptorStart_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (_floatingWindowInterceptorManager != null)
- {
- _floatingWindowInterceptorManager.Start();
- UpdateFloatingWindowInterceptorUI();
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogToFile($"启动悬浮窗拦截失败: {ex.Message}", LogHelper.LogType.Error);
- }
- }
-
- ///
- /// 停止拦截按钮点击
- ///
- private void BtnFloatingWindowInterceptorStop_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (_floatingWindowInterceptorManager != null)
- {
- _floatingWindowInterceptorManager.Stop();
- UpdateFloatingWindowInterceptorUI();
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogToFile($"停止悬浮窗拦截失败: {ex.Message}", LogHelper.LogType.Error);
- }
- }
-
- ///
- /// 手动扫描按钮点击
- ///
- private void BtnFloatingWindowInterceptorScan_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (_floatingWindowInterceptorManager != null)
- {
- _floatingWindowInterceptorManager.ScanOnce();
- UpdateFloatingWindowInterceptorUI();
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogToFile($"手动扫描失败: {ex.Message}", LogHelper.LogType.Error);
- }
- }
///
/// 恢复所有窗口按钮点击
@@ -391,73 +343,6 @@ namespace Ink_Canvas
LogHelper.WriteLogToFile($"恢复所有窗口失败: {ex.Message}", LogHelper.LogType.Error);
}
}
-
- ///
- /// 调试列出窗口按钮点击
- ///
- private void BtnFloatingWindowInterceptorDebug_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (_floatingWindowInterceptorManager != null)
- {
- // 更新状态显示
- TextBlockFloatingWindowInterceptorStatus.Text = "正在调试扫描窗口...";
-
- _floatingWindowInterceptorManager.DebugListAllWindows();
-
- // 更新状态显示
- TextBlockFloatingWindowInterceptorStatus.Text = "调试扫描完成,请查看日志文件";
-
- LogHelper.WriteLogToFile("用户点击了调试列出窗口按钮", LogHelper.LogType.Event);
- }
- else
- {
- LogHelper.WriteLogToFile("拦截器管理器未初始化", LogHelper.LogType.Warning);
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogToFile($"调试列出窗口失败: {ex.Message}", LogHelper.LogType.Error);
- TextBlockFloatingWindowInterceptorStatus.Text = "调试扫描失败";
- }
- }
-
- ///
- /// 测试拦截按钮点击
- ///
- private void BtnFloatingWindowInterceptorTest_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (_floatingWindowInterceptorManager != null)
- {
- // 更新状态显示
- TextBlockFloatingWindowInterceptorStatus.Text = "正在测试拦截功能...";
-
- // 启用测试规则
- _floatingWindowInterceptorManager.SetInterceptRule(FloatingWindowInterceptor.InterceptType.SeewoWhiteboard3Floating, true);
-
- // 执行一次扫描
- _floatingWindowInterceptorManager.ScanOnce();
-
- // 更新状态显示
- TextBlockFloatingWindowInterceptorStatus.Text = "测试拦截完成,请查看日志文件";
-
- LogHelper.WriteLogToFile("用户点击了测试拦截按钮", LogHelper.LogType.Event);
- }
- else
- {
- LogHelper.WriteLogToFile("拦截器管理器未初始化", LogHelper.LogType.Warning);
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogToFile($"测试拦截失败: {ex.Message}", LogHelper.LogType.Error);
- TextBlockFloatingWindowInterceptorStatus.Text = "测试拦截失败";
- }
- }
-
#endregion
}
}
\ No newline at end of file