improve:PPT模块

This commit is contained in:
2025-07-20 19:40:10 +08:00
parent 1f83c84a7e
commit 1f0b5cebeb
+8 -18
View File
@@ -1364,36 +1364,25 @@ namespace Ink_Canvas {
{ {
try try
{ {
// 检查所有WPS相关进程(wpp、wps、et)是否有前台窗口 if (wppProcess != null)
string[] wpsProcessNames = { "wpp", "wps", "et" };
var wpsPids = new System.Collections.Generic.HashSet<int>();
foreach (var name in wpsProcessNames)
{ {
foreach (var proc in System.Diagnostics.Process.GetProcessesByName(name)) bool hasVisibleWppWindow = false;
{
wpsPids.Add(proc.Id);
}
}
bool hasVisibleWpsWindow = false;
EnumWindows((hWnd, lParam) => EnumWindows((hWnd, lParam) =>
{ {
try try
{ {
uint windowProcessId; uint windowProcessId;
GetWindowThreadProcessId(hWnd, out windowProcessId); GetWindowThreadProcessId(hWnd, out windowProcessId);
if (wpsPids.Contains((int)windowProcessId)) if ((int)windowProcessId == wppProcess.Id)
{ {
// 检查窗口是否可见
if (IsWindowVisible(hWnd)) if (IsWindowVisible(hWnd))
{ {
// 检查窗口标题是否为空
var windowTitle = new System.Text.StringBuilder(256); var windowTitle = new System.Text.StringBuilder(256);
GetWindowText(hWnd, windowTitle, 256); GetWindowText(hWnd, windowTitle, 256);
var title = windowTitle.ToString().Trim(); var title = windowTitle.ToString().Trim();
if (!string.IsNullOrEmpty(title)) if (!string.IsNullOrEmpty(title))
{ {
hasVisibleWpsWindow = true; hasVisibleWppWindow = true;
return false; // 找到一个就停止枚举 return false; // 找到一个就停止枚举
} }
} }
@@ -1403,12 +1392,13 @@ namespace Ink_Canvas {
return true; return true;
}, IntPtr.Zero); }, IntPtr.Zero);
// 只要没有任何WPS相关可见窗口,就允许Kill // 只要当前wpp进程没有可见窗口,就允许Kill
return hasVisibleWpsWindow; return hasVisibleWppWindow;
}
} }
catch (Exception ex) catch (Exception ex)
{ {
LogHelper.WriteLogToFile($"检查WPS前台窗口失败: {ex.ToString()}", LogHelper.LogType.Error); LogHelper.WriteLogToFile($"检查WPP窗口失败: {ex.ToString()}", LogHelper.LogType.Error);
} }
return false; // 出错时,默认允许Kill return false; // 出错时,默认允许Kill
} }