From 69d69b351aba135f2b92230766133f0c3c504ef9 Mon Sep 17 00:00:00 2001
From: zimoyin <2556608754@qq.com>
Date: Tue, 13 Oct 2026 16:33:50 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0/=E6=8B=BE=E5=8F=96=E6=8E=A7?=
=?UTF-8?q?=E4=BB=B6=E6=97=B6=E9=A2=84=E8=A7=88=E7=9A=84=E5=80=BC=E4=B9=9F?=
=?UTF-8?q?=E6=8C=89=E3=80=8C=E6=96=87=E6=9C=AC=E5=86=85=E5=AE=B9=E3=80=8D?=
=?UTF-8?q?=E5=8F=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
之前预览值取的是 UIA Name,富文本/记事本文档会显示成「文本编辑器」「RichEdit Control」
这类标题,让人以为取值键配错了(实际回读是正确的)。现在预览与取值走同一套降级
顺序(Value → Text → Name),全部失败时退回 Name,且不抛异常。
实测(真实 Windows 11 记事本,跨进程只读探测):
- 树里有 Document「文本编辑器」,矩形有效,拾取精确命中该节点
- 拾取后保存:Path=/Window[1]/Pane[@ClassName='NotepadTextBox']/Document[@ClassName='RichEditD2DPT']
ValueKey=文本内容,预览值="agfa\r\raaaaa"
- 回读同一配置:found=true,value="agfa\r\raaaaa"
回归 27/27 通过
---
.../Services/ControlLocatorBuilder.cs | 4 ++-
.../Services/ControlValueReader.cs | 30 +++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/src/pacs_win_uia/Services/ControlLocatorBuilder.cs b/src/pacs_win_uia/Services/ControlLocatorBuilder.cs
index bbc1580..3c3843e 100644
--- a/src/pacs_win_uia/Services/ControlLocatorBuilder.cs
+++ b/src/pacs_win_uia/Services/ControlLocatorBuilder.cs
@@ -286,7 +286,9 @@ namespace pacs_win_uia.Services
if (node.Uia == null) { result.Note = "节点缺少 UIA 数据。"; return result; }
result.ValueKey = ControlValueKeys.TextContent;
result.RuntimeId = node.Uia.RuntimeId;
- result.Value = node.Uia.Name;
+ // 预览值:和取值键「文本内容」一致(Value → Text → Name),
+ // 否则富文本/输入框会显示成 "RichEdit Control" 这类标题,让人以为取错了。
+ result.Value = ControlValueReader.TryGetTextContent(node.Uia);
break;
}
ControlPath.PreparePaths(root);
diff --git a/src/pacs_win_uia/Services/ControlValueReader.cs b/src/pacs_win_uia/Services/ControlValueReader.cs
index 793997f..a3fc784 100644
--- a/src/pacs_win_uia/Services/ControlValueReader.cs
+++ b/src/pacs_win_uia/Services/ControlValueReader.cs
@@ -249,6 +249,36 @@ namespace pacs_win_uia.Services
}
+
+ ///
+ /// 供"添加控件/拾取"时预览用:按 Value → Text → Name 取内容,失败返回 null。
+ /// 不抛异常;只在已经需要跨进程调用的路径上使用(新增监控项时)。
+ ///
+ // 预览用:拿到就返回内容,拿不到返回 null(绝不抛)。
+ public static string TryGetTextContent(UiaElementInfo info)
+ {
+ if (info == null)
+ {
+ return null;
+ }
+
+ try
+ {
+ string value;
+ string error;
+ if (TryReadUiaTextContent(info, new ListReadOptions(), out value, out error))
+ {
+ return value;
+ }
+ }
+ catch (Exception)
+ {
+ // 预览失败不影响保存:退回 Name。
+ }
+
+ return info.Name;
+ }
+
///
/// 读取"这个控件的内容文本"。顺序:ValuePattern → TextPattern → 快照 Name。
/// 这样输入框(内容在 Value)、富文本(内容在 Text)和把内容放在 Name 里的客户端都能拿到值。