选中行/焦点行语法、列表信息键、拾取层级框、控件属性补全

1) 新增「选中行/焦点行」语法,控件监控新增列表信息
   - XPath 快照新增状态属性:@IsSelected / @IsFocused / @IsOffscreen / @IsEnabled
     例如 /Window[1]//DataGrid[@AutomationId='x']/DataItem[@IsSelected='true']
   - IsSelected 随控件树一起从缓存读(SelectionItemPattern);对只在容器上暴露
     SelectionPattern 的提供者(实测 WinForms ListView/DataGridView),树读完后
     由容器反推每个子项的选中状态,@IsSelected 与「选中状态」取值因此可用
   - 新增取值键:列表行数 / 列表列数 / 列表选中项数(Grid → Table → Selection)
   - 控件属性新增「列表概况」(行×列 + 选中项数 + 首项文本)

2) 拾取时显示层级:蓝框=光标所在窗口,黄框=向上遍历的控件链
   - PointPickResult 增加 HierarchyFrames;TargetProbeService 填蓝色窗口层 +
     UiAutomationService.DescribeAncestorFrames 产出的黄色控件链(最多 6 层)
   - 新增 UI/PickHierarchyOverlayForm:跟随锚点窗口、只读 GetWindowRect、
     最小化/关闭即收起、置顶不抢焦点、点击穿透
   - CrosshairPicker 预览改用层级框;只有 Win32/MSAA 信息时退回原来的单框高亮

3) 控件属性按 UIA/Win32 分类补全(没有的就新增)
   - UIA:父元素、RawView/ControlView/ContentView 子元素数、RangeValue、
     Toggle 状态、选中情况、列表概况(全部按需读取,选中节点时才跨进程)
   - Win32:样式 GWL_STYLE、扩展样式 GWL_EXSTYLE、启用、最大化、层级关系
     (父窗口 / 直接子窗口数 / 同类序号)
   - GetWindowStyle 原本读的其实是 GWL_EXSTYLE,已正名为 GetWindowExStyle,
     GWL_STYLE 用新方法读取

实测(跨进程,目标为夹具/记事本):
- 夹具列表选中第 2 行:DataItem[2] IsSelected=True;@IsSelected='true' 唯一命中并
  取到「项目 2」;列表行数=3、列表列数=2、列表选中项数=1
- 拾取夹具列表行:7 层框(1 蓝窗口 + 6 黄控件链),覆盖层实际绘制并截图确认
- 记事本文档:控件属性显示 文本内容="agfa\r\raaaaa"(Name 是「文本编辑器」)

回归 29/29 通过
This commit is contained in:
zimoyin
2026-10-13 19:19:16 +08:00
parent d7e50675f0
commit ebbf9e1335
19 changed files with 1216 additions and 6 deletions
+33 -2
View File
@@ -41,6 +41,9 @@ namespace UiaFixture
private readonly ListView _list;
private readonly DataGridView _grid;
/// <summary>启动时选中列表的第几行(0-based,-1 表示不选)。给自动化验证用。</summary>
public int SelectRowOnStartup { get; set; }
public FixtureForm()
{
Text = "UIA 测试夹具";
@@ -124,6 +127,9 @@ namespace UiaFixture
_list.Items.Add(new ListViewItem(new[] { "项目 " + index, "ID" + index }));
}
// 让测试能预先选中某一行(例如验证 XPath 的 @IsSelected / @IsFocused)。
SelectRowOnStartup = 0;
_tree = new TreeView
{
Name = "FixtureTreeView",
@@ -197,6 +203,18 @@ namespace UiaFixture
tabs.TabPages.Add(gridPage);
tabs.TabPages.Add(nestedPage);
Controls.Add(tabs);
Shown += delegate
{
if (SelectRowOnStartup < 0 || SelectRowOnStartup >= _list.Items.Count)
{
return;
}
_list.Items[SelectRowOnStartup].Selected = true;
_list.Items[SelectRowOnStartup].Focused = true;
_list.Select();
_list.EnsureVisible(SelectRowOnStartup);
};
// A second top-level window so "which window" itself can be tested.
var secondary = new Form
@@ -230,11 +248,24 @@ namespace UiaFixture
internal static class Program
{
[STAThread]
private static void Main()
private static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FixtureForm());
var form = new FixtureForm();
// UiaFixture.exe --select-row 2 → 启动时选中列表第 2 行(1-based),
// 用于验证 XPath 的 @IsSelected/@IsFocused 与"选中行"取值。
if (args != null && args.Length >= 2 && string.Equals(args[0], "--select-row", StringComparison.Ordinal))
{
int oneBased;
if (int.TryParse(args[1], out oneBased))
{
form.SelectRowOnStartup = oneBased - 1;
}
}
Application.Run(form);
}
}
}