diff --git a/docs/XPath定位.md b/docs/XPath定位.md
index 6ce7a63..55ae8de 100644
--- a/docs/XPath定位.md
+++ b/docs/XPath定位.md
@@ -225,6 +225,7 @@ XPath 中的 `Edit`、`Button` 等来自 UIA 控件类型。不同来源也会
| `列表行数` | 行数(GridPattern 优先,其次 TablePattern) |
| `列表列数` | 列数 |
| `列表选中项数` | 当前选中项数 |
+| `选中行文本` | 当前选中那一行的文字(在列表容器上直接读,不用先选行) |
需要完整行列数据时仍然用「读取选中控件列表」。
diff --git a/docs/代码导览.md b/docs/代码导览.md
index 4459e5e..8f2dbe0 100644
--- a/docs/代码导览.md
+++ b/docs/代码导览.md
@@ -65,7 +65,7 @@ MainForm(UI/MainForm.cs) 三栏主界面:窗口列表 | 控件树/列
| 悬浮条外观(自绘/透明) | `UI/FloatingToolbarForm.cs` | layered window,注意 GDI 释放 |
| 遮挡/可见性判断 | `Services/WindowVisibility.cs` | 两个 API 用途不同,见文件头 |
| 高亮框/跟随 | `Services/HighlightFollower.cs` | 跟随锚点窗口的相对偏移 |
-| 全部控件框绘制 | `UI/NodeMapOverlayForm.cs` | 只在前台窗口且未遮挡处绘制 |
+| 全部控件框绘制 / 侧边按钮与过滤 | `UI/NodeMapOverlayForm.cs` | 只在前台窗口且未遮挡处绘制;点框即选中控件树节点并刷新控件属性 |
| 拾取器 | `Picker/CrosshairPicker.cs` + `UI/PickerOverlayForm.cs` | 不抢焦点、吞左键 |
| 单实例/转发 | `Services/SingleInstanceService.cs` + `Program.cs` | Mutex + 命名管道 |
| 无界面读取 | `Services/HeadlessConfigReader.cs` | 每条独立计时,统计口径在文件头 |
@@ -105,6 +105,16 @@ MainForm(UI/MainForm.cs) 三栏主界面:窗口列表 | 控件树/列
---
+## 四·三、空树自动开无障碍(浏览器/CEF/UWP)
+
+读到**空树 / 只有窗口边框 / 里面有渲染窗口却没有子树**时,`ControlTreeService` 会自动请求目标开启无障碍(`AccessibilityActivationService`)并等 900ms 重读一次:
+
+- 目标确实开了:节点数变多,采用新结果,状态栏说明"重读后节点 N → M";
+- 目标没暴露:如实说明"该目标没有向系统暴露无障碍树",不会假装读到了;
+- 同一窗口 60 秒内只自动激活一次;
+- 主程序里**只嵌了一块浏览器区域**(部分 DOM)同样适用:激活只影响那块渲染窗口,重读后它和原生控件一起出现在同一棵树里,**不会改写根窗口**;
+- 不想要工具动目标:设置 →「界面」里关掉"读到空树时自动请求目标开启无障碍"。
+
## 四·五、配置文件位置(都在 exe 同目录)
| 文件 | 用途 |
diff --git a/src/pacs_win_uia/Models/ControlLocator.cs b/src/pacs_win_uia/Models/ControlLocator.cs
index 0bfe1ec..1c40912 100644
--- a/src/pacs_win_uia/Models/ControlLocator.cs
+++ b/src/pacs_win_uia/Models/ControlLocator.cs
@@ -177,6 +177,12 @@ namespace pacs_win_uia.Models
public const string ListSelectedCount = "列表选中项数";
+ ///
+ /// 跨来源键(UIA):列表容器上直接读「当前选中那一行的文字」。
+ /// 用它在监控里盯住"现在选中的是哪一行",不必写 XPath 选行再取值。
+ ///
+ public const string SelectedRowText = "选中行文本";
+
/// 跨来源键:这个控件是不是被选中的那一个。
public const string Selected = "选中状态";
@@ -198,7 +204,7 @@ namespace pacs_win_uia.Models
TextContent, "Name", "AutomationId", "ControlType", "ClassName", "FrameworkId",
"RuntimeId", "IsEnabled", "IsOffscreen", "BoundingRectangle",
"Value", "Text", Selected, "IsSelected", Focused, "HasKeyboardFocus",
- ListRowCount, ListColumnCount, ListSelectedCount
+ ListRowCount, ListColumnCount, ListSelectedCount, SelectedRowText
};
// Msaa:MSAA 来源可读取的属性键列表。
diff --git a/src/pacs_win_uia/Services/ControlValueReader.cs b/src/pacs_win_uia/Services/ControlValueReader.cs
index efd3304..3d8b3fe 100644
--- a/src/pacs_win_uia/Services/ControlValueReader.cs
+++ b/src/pacs_win_uia/Services/ControlValueReader.cs
@@ -232,6 +232,8 @@ namespace pacs_win_uia.Services
return TryReadUiaListDimension(info, false, out value, out error);
case ControlValueKeys.ListSelectedCount:
return TryReadUiaSelectionCount(info, out value, out error);
+ case ControlValueKeys.SelectedRowText:
+ return TryReadUiaSelectedRowText(info, options, out value, out error);
// 选中状态:支持“选中状态”(Selected) 与 “IsSelected” 两个别名。
case ControlValueKeys.Selected:
case "IsSelected":
@@ -287,6 +289,96 @@ namespace pacs_win_uia.Services
}
+
+ ///
+ /// 列表容器上的「选中行文本」:取 SelectionPattern 的第一个选中项,再按
+ /// Value → Text → Name 读它的内容(与「文本内容」同一套顺序)。
+ /// 没有选中项时明确报"当前没有选中行",而不是给一个空字符串。
+ ///
+ // 选中行文本:容器 → 第一个选中项 → 该行内容。
+ private static bool TryReadUiaSelectedRowText(UiaElementInfo info, ListReadOptions options,
+ out string value, out string error)
+ {
+ value = null;
+ error = null;
+ AutomationElement element = info == null ? null : info.Element;
+ if (element == null)
+ {
+ error = "UIA 元素引用不可用(可能是回读时未重新绑定)。";
+ return false;
+ }
+
+ try
+ {
+ object pattern;
+ if (!element.TryGetCurrentPattern(SelectionPattern.Pattern, out pattern))
+ {
+ error = "该控件不支持 SelectionPattern,读不到选中行(列表行本身可以用 XPath 的 @IsSelected 选)。";
+ return false;
+ }
+
+ AutomationElement[] items = ((SelectionPattern)pattern).Current.GetSelection();
+ if (items == null || items.Length == 0)
+ {
+ error = "该列表当前没有选中行。";
+ return false;
+ }
+
+ AutomationElement row = items[0];
+ // 先试模式值(输入/富文本类的行),再退回名称(普通列表行)。
+ foreach (string key in new[] { "Value", "Text" })
+ {
+ try
+ {
+ object rowPattern;
+ if (string.Equals(key, "Value", StringComparison.Ordinal) &&
+ row.TryGetCurrentPattern(ValuePattern.Pattern, out rowPattern))
+ {
+ string candidate = ((ValuePattern)rowPattern).Current.Value;
+ if (!string.IsNullOrEmpty(candidate))
+ {
+ value = candidate;
+ return true;
+ }
+
+ continue;
+ }
+
+ if (string.Equals(key, "Text", StringComparison.Ordinal) &&
+ row.TryGetCurrentPattern(TextPattern.Pattern, out rowPattern))
+ {
+ int maxLength = options == null ? 32768 : options.MaxTextLength;
+ string candidate = ((TextPattern)rowPattern).DocumentRange.GetText(Math.Max(1, maxLength));
+ if (!string.IsNullOrEmpty(candidate))
+ {
+ value = candidate.TrimEnd('\r', '\n');
+ return true;
+ }
+ }
+ }
+ catch (Exception)
+ {
+ // 该行不支持这个模式:继续试下一个来源。
+ }
+ }
+
+ string name = row.Current.Name;
+ if (!string.IsNullOrEmpty(name))
+ {
+ value = name;
+ return true;
+ }
+
+ error = "选中行没有可读的文本(Value/Text/Name 都为空)。";
+ return false;
+ }
+ catch (Exception ex)
+ {
+ error = "读取选中行文本失败:" + ex.GetType().Name + ": " + ex.Message;
+ return false;
+ }
+ }
+
///
/// 列表行数 / 列数:优先 GridPattern,其次 TablePattern(两者都有的控件以 Grid 为准)。
/// 只有容器(List/DataGrid/Table/Tree)才支持,普通控件会明确报"不是列表"。
diff --git a/src/pacs_win_uia/UI/MainForm.cs b/src/pacs_win_uia/UI/MainForm.cs
index 83ec1d4..3f0544a 100644
--- a/src/pacs_win_uia/UI/MainForm.cs
+++ b/src/pacs_win_uia/UI/MainForm.cs
@@ -535,17 +535,30 @@ namespace pacs_win_uia
_locateFollower.Hidden += LocateFollowerOnHidden;
_nodeMapOverlay = new NodeMapOverlayForm { RefreshIntervalMs = _settings.Ui.TreeRefreshIntervalMs };
_nodeMapOverlay.MapExited += delegate { _nodeMapItem.Checked = false; };
+ // 点击控件框:在控件树里展开并选中该节点,同时更新控件属性;顺带把 path 复制到剪贴板。
+ // 节点不在当前树里(例如框属于另一个窗口的树)时,也要更新控件属性,不能什么都不发生。
_nodeMapOverlay.NodeSelected += delegate(object sender, NodeMapSelectionEventArgs e)
{
var node = e.Node as ControlTreeNode;
if (node == null) return;
- SelectTreeNodeFor(node);
+
+ bool selectedInTree = SelectTreeNodeFor(node);
+ _propertyGrid.SelectedObject = SelectedObjectFor(node);
+ _monitorEditor.SetCurrentNode(node, _inspectedWindow);
+ ShowNodeProperties(node);
+ UpdateSelectedPathText(node);
+
try
{
if (!string.IsNullOrEmpty(e.Path)) Clipboard.SetText(e.Path);
- SetStatus("已复制该框的 path:" + e.Path + "(滚轮可切换重叠节点)", null);
+ SetStatus("已选中该框的控件:" + node.Describe()
+ + (selectedInTree ? "(控件树已展开并选中)" : "(该节点不在当前控件树里,只更新了控件属性)")
+ + ";path 已复制:" + e.Path + "(滚轮可切换重叠节点)", null);
+ }
+ catch (Exception ex)
+ {
+ SetStatus("复制 path 失败。", ex);
}
- catch (Exception ex) { SetStatus("复制 path 失败。", ex); }
};
_statusText = new TextBox
{
diff --git a/src/pacs_win_uia/UI/NodeMapOverlayForm.cs b/src/pacs_win_uia/UI/NodeMapOverlayForm.cs
index db1ca92..9fb1fe2 100644
--- a/src/pacs_win_uia/UI/NodeMapOverlayForm.cs
+++ b/src/pacs_win_uia/UI/NodeMapOverlayForm.cs
@@ -23,8 +23,28 @@
// 框坐标以锚定顶层窗口左上角为原点存成相对偏移(Entry.Offset);RefreshMap 时若目标不可见/
// 被完全遮挡/非前台,就隐藏表面(HideSurfaces)并退出选取模式,目标恢复后自动复现。
//
-// “要改什么就改哪里”:快照/几何 → ReplaceItems / RefreshMap;选取与钩子 → SetSelectionMode /
-// MouseHookCallback / KeyboardHookCallback;绘制 → OnPaint。
+// 侧栏(NodeMapActionsForm)新增的联动功能:
+// · 父节点 / 上一个 / 下一个:用 MapItems 自身的 Node 引用推父子关系(items 覆盖整棵树,
+// 每个 Node 的 Children 也在 items 里),不依赖 MainForm;点击后发 NodeSelected,并把整条
+// 祖先链加粗高亮(其余框变淡)。
+// · 点框联动:点/滚轮选中一个框后同样发 NodeSelected(带 Node/Index/Path/ScreenPoint),
+// MainForm 负责在控件树里选中并刷新属性(现有行为,本次只是把“当前项”也记进覆盖层)。
+// · 显示框的信息:类型 / 名称 / 宽×高 / (X,Y) / 层级路径,显示鼠标下优先、否则当前选中的框。
+// · 过滤与搜索:搜索词 + 控件类型下拉(类型从 items 收集)+“仅选中及其祖先/后代”勾选。
+// · 悬停标签:只在鼠标下的那个框旁画一个“类型:名称 宽×高”小标签(120-300ms 定时器读
+// Cursor.Position 在内存里命中测试,不装鼠标钩子)。
+// · 其它:一键复制当前框 path、显示/隐藏标签开关。
+//
+// 硬性约束(勿破坏):不抢焦点/不激活/不吞普通模式点击——覆盖层保留
+// WS_EX_NOACTIVATE|WS_EX_TRANSPARENT + HTTRANSPARENT;侧栏只是 NOACTIVATE(可点按钮,不点击穿透)。
+// 目标最小化/关闭/被别的程序完全遮挡时的隐藏逻辑保持不变;本工具自身窗口不算遮挡。
+// 每帧只读 GetWindowRect(RefreshMap),过滤/命中测试全在内存里,不新增跨进程 UIA 调用。
+// 搜索框/类型下拉在 NOACTIVATE 侧栏上通过 AttachThreadInput 抢到键盘焦点(见 NodeMapInputFocus),
+// 这样能输入但不会激活侧栏、也不会抢走目标窗口的激活态。
+//
+// “要改什么就改哪里”:快照/几何/父子关系 → ReplaceItems / RefreshMap;选取与钩子 → SetSelectionMode /
+// MouseHookCallback / KeyboardHookCallback;绘制(框、祖先链、悬停标签)→ OnPaint;过滤 → ApplyFilter /
+// MatchesFilter;导航 → GoParent / GoSibling;侧栏控件与布局 → NodeMapActionsForm。
// ============================================================================
using System;
using System.Collections.Generic;
@@ -32,12 +52,101 @@ using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;
+using System.Text;
using System.Windows.Forms;
using pacs_win_uia.Interop;
+using pacs_win_uia.Models;
using pacs_win_uia.Services;
namespace pacs_win_uia.UI
{
+ // -------------------------------------------------------------------------
+ // NodeMapNodeInfo —— 从覆盖层持有的 Node(object,实际是 ControlTreeNode)里只读地取显示信息。
+ // 只读内存快照字段(Uia/Msaa/Window),绝不触发任何跨进程调用,可安全用于每帧的过滤/标签。
+ // -------------------------------------------------------------------------
+ internal static class NodeMapNodeInfo
+ {
+ /// 把 Node 安全转成 ControlTreeNode(不是则返回 null)。
+ internal static ControlTreeNode AsNode(object node) { return node as ControlTreeNode; }
+
+ /// 显示名称:UIA.Name → MSAA.Name → 窗口标题。
+ internal static string GetName(object node)
+ {
+ ControlTreeNode n = node as ControlTreeNode;
+ if (n == null) return null;
+ if (n.Uia != null && !string.IsNullOrEmpty(n.Uia.Name)) return n.Uia.Name;
+ if (n.Msaa != null && !string.IsNullOrEmpty(n.Msaa.Name)) return n.Msaa.Name;
+ if (n.Window != null && !string.IsNullOrEmpty(n.Window.Title)) return n.Window.Title;
+ return null;
+ }
+
+ /// 类型文本:UIA.ControlType → MSAA.RoleText → 按来源给个通用名。
+ internal static string GetType(object node)
+ {
+ ControlTreeNode n = node as ControlTreeNode;
+ if (n == null) return null;
+ if (n.Uia != null && !string.IsNullOrEmpty(n.Uia.ControlType)) return n.Uia.ControlType;
+ if (n.Msaa != null && !string.IsNullOrEmpty(n.Msaa.RoleText)) return n.Msaa.RoleText;
+ switch (n.Source)
+ {
+ case ControlTreeSource.Win32: return "Win32窗口";
+ case ControlTreeSource.Msaa: return "MSAA节点";
+ default: return "UIA控件";
+ }
+ }
+
+ /// 类名:UIA.ClassName → 窗口类名。
+ internal static string GetClassName(object node)
+ {
+ ControlTreeNode n = node as ControlTreeNode;
+ if (n == null) return null;
+ if (n.Uia != null && !string.IsNullOrEmpty(n.Uia.ClassName)) return n.Uia.ClassName;
+ if (n.Window != null) return n.Window.ClassName;
+ return null;
+ }
+
+ /// AutomationId(只有 UIA 节点有)。
+ internal static string GetAutomationId(object node)
+ {
+ ControlTreeNode n = node as ControlTreeNode;
+ return n == null || n.Uia == null ? null : n.Uia.AutomationId;
+ }
+ }
+
+ // -------------------------------------------------------------------------
+ // NodeMapInputFocus —— 让 NOACTIVATE 侧栏上的输入控件(搜索框/下拉)能收到键盘输入,
+ // 但不激活侧栏、不抢目标窗口的激活态。做法:临时把本线程附到前台线程的输入队列,
+ // SetFocus 后再分离(经典技巧)。失败时静默放弃(按钮/鼠标选择仍可用)。
+ // -------------------------------------------------------------------------
+ internal static class NodeMapInputFocus
+ {
+ [DllImport("user32.dll", SetLastError = false)]
+ private static extern IntPtr SetFocus(IntPtr hWnd);
+ [DllImport("user32.dll", SetLastError = false)]
+ private static extern bool AttachThreadInput(uint idAttach, uint idAttachTo, bool fAttach);
+ [DllImport("kernel32.dll", SetLastError = false)]
+ private static extern uint GetCurrentThreadId();
+
+ /// 把键盘焦点强制给到指定控件(不激活其顶层窗口)。
+ internal static void ForceFocus(Control control)
+ {
+ if (control == null || control.IsDisposed || !control.IsHandleCreated) return;
+ IntPtr foreground = NativeMethods.GetForegroundWindow();
+ uint processId;
+ uint foregroundThread = foreground == IntPtr.Zero ? 0 :
+ NativeMethods.GetWindowThreadProcessId(foreground, out processId);
+ uint currentThread = GetCurrentThreadId();
+ bool attached = false;
+ if (foregroundThread != 0 && foregroundThread != currentThread)
+ attached = AttachThreadInput(foregroundThread, currentThread, true);
+ try { SetFocus(control.Handle); }
+ finally
+ {
+ if (attached) AttachThreadInput(foregroundThread, currentThread, false);
+ }
+ }
+ }
+
/// An immutable tree-refresh snapshot; Bounds are screen coordinates, Node is caller-owned.
/// 一次树刷新后的不可变快照:屏幕矩形 + 调用方拥有的节点对象;供覆盖层只读使用。
public class NodeMapItem
@@ -106,6 +215,17 @@ namespace pacs_win_uia.UI
internal NodeMapItem Item;
/// 相对锚定窗口左上角的偏移矩形(跟随窗口移动)。
internal Rectangle Offset;
+ // ---- 以下为过滤/标签/信息面板用的预计算文本(只在 ReplaceItems 时算一次,内存内使用)----
+ /// 显示名称(来自 Node)。
+ internal string Name;
+ /// 类型(来自 Node)。
+ internal string Type;
+ /// 类名(来自 Node)。
+ internal string ClassName;
+ /// AutomationId(来自 Node)。
+ internal string AutomationId;
+ /// 是否通过当前过滤(false 则不画、不参与命中测试)。
+ internal bool Visible = true;
}
/// UI 线程 300ms 刷新定时器。
@@ -137,6 +257,36 @@ namespace pacs_win_uia.UI
/// 是否已有 _candidatePoint(用于“同点同候选”判断)。
private bool _hasCandidatePoint;
+ // ---- 选中/导航/父子关系(全部由 items 自身推导,不依赖 MainForm)----
+ /// Node 引用 → Entry(引用相等;用于按节点找回条目、推父子关系)。
+ private readonly Dictionary