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 里的客户端都能拿到值。