监控列表定位后必然联动控件树,并把本工具窗口排除出定位框遮挡判断

用户反馈:在控件监控列表里定位显示已定位到「control」,但控件树不展开也不选中。
根因:MonitorEditorOnControlLocated 在画不出高亮框时直接 return,跳过了
SelectTreeNodeFor/EnsureTreeShows;而画不出框的常见原因就是本工具自己的窗口
压在目标上(CanShowLocateFrame 用的是严格可见性)。

- 定位成功一律先展开并选中控件树节点,画框与否只影响高亮框
- 画不出框时状态栏说明原因,但不再吞掉树联动
- HighlightFollower/CanShowLocateFrame 与本工具悬浮条统一规则:本工具自身
  窗口不算遮挡,只有别的程序挡住目标才隐藏定位框
- EnsureTreeShows 返回已去读另一个窗口的树,避免状态栏提示被覆盖
- 实测(进程内宿主+镜像树模拟解析器返回的另一实例):定位后树中选中该节点、
  祖先展开、切到控件树页、Path 横条同步;无矩形时同样选中
- 回归测试 23/23 通过

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
zimoyin
2026-10-13 16:10:25 +08:00
parent a77e1b163a
commit 695b98dd35
3 changed files with 37 additions and 18 deletions
+1 -1
View File
@@ -320,7 +320,7 @@ RuntimeId 和 HWND 适合当前运行中的重新绑定,不适合直接作为
### 直接编辑 ### 直接编辑
在“控件监控列表”中: 在“控件监控列表”中,点击任意一行(或“定位到控件”按钮)都会:先在屏幕上高亮该控件,**同时在控件树里展开祖先并选中该节点**,控件树下方的 Path 横条也会同步显示它的 XPath。即使当前画不出高亮框(目标最小化、被别的程序遮住、或控件没有矩形),控件树的联动照样发生。
1. 选中 `控件Path` 单元格; 1. 选中 `控件Path` 单元格;
2. 按 `F2` 或直接输入; 2. 按 `F2` 或直接输入;
@@ -233,7 +233,9 @@ namespace pacs_win_uia.Services
} }
string visibilityReason; string visibilityReason;
if (!WindowVisibility.IsVisibleOnScreen(_anchor, rect, _ownProcessId, out visibilityReason)) // 与本工具的悬浮条同一套规则:只有"别的程序"挡住目标才收起框,本工具自己的窗口
// (主界面 / 设置窗口)不算遮挡——否则在工具里定位时框永远看不到。
if (!WindowVisibility.IsVisibleOnScreen(_anchor, rect, _ownProcessId, true, out visibilityReason))
{ {
// Minimized, hidden, covered or off-screen: take the box away, but keep tracking so it // Minimized, hidden, covered or off-screen: take the box away, but keep tracking so it
// comes back when the operator can see the target again. The reason is reported once. // comes back when the operator can see the target again. The reason is reported once.
+33 -16
View File
@@ -3300,7 +3300,14 @@ namespace pacs_win_uia
string reason; string reason;
if (!CanShowLocateFrame(e, out reason)) if (!CanShowLocateFrame(e, out reason))
{ {
HideLocateFrame(reason); // 画不出框(最小化 / 被别的程序挡住 / 没有矩形)不是"定位失败":控件树照样要展开
// 并选中,否则操作者点了半天看不到任何联动。
_locateFollower.Hide(reason);
_locatedDefinition = null;
_locatedNode = null;
bool selectedWithoutFrame = SelectTreeNodeFor(e.Node);
EnsureTreeShows(e);
SetStatus((selectedWithoutFrame ? "已在控件树里展开并选中该控件。" : "已定位到该控件。") + reason, null);
return; return;
} }
@@ -3311,14 +3318,20 @@ namespace pacs_win_uia
e.AnchorWindow, e.AnchorWindow,
BuildBoundsResolver(e.Definition, e.Node), BuildBoundsResolver(e.Definition, e.Node),
"定位框"); "定位框");
SetStatus(e.UsedFallback // 定位成功就一定有联动:在控件树里展开祖先并选中该节点(与"能不能画框"无关)。
// 若节点属于另一个窗口,则改为去读那个窗口的树,读完再选中(它的提示优先)。
bool selected = SelectTreeNodeFor(e.Node);
if (EnsureTreeShows(e))
{
return;
}
SetStatus((e.UsedFallback
? "已高亮该控件(" + e.Bounds + "),但这次是用容错规则定位的,框的位置可能不准:" ? "已高亮该控件(" + e.Bounds + "),但这次是用容错规则定位的,框的位置可能不准:"
+ "建议在界面里重新添加该控件;再点一次行头可隐藏。" + "建议在界面里重新添加该控件。"
: "已在屏幕上高亮该控件(" + e.Bounds + ");再点一次行头可隐藏。", null); : "已在屏幕上高亮该控件(" + e.Bounds + ")。")
// Selecting the node may find the tree belongs to another window, in which case that + (selected ? "控件树已展开并选中。" : "控件树里没有对应节点(可切换控件树来源或重读窗口)。")
// window's tree is read and this message is replaced by the more specific one. + "再点一次行头可隐藏。", null);
SelectTreeNodeFor(e.Node);
EnsureTreeShows(e);
} }
/// <summary> /// <summary>
@@ -3425,33 +3438,37 @@ namespace pacs_win_uia
/// a row has to end with the control visible in the tree, so the tree of its own window is read /// a row has to end with the control visible in the tree, so the tree of its own window is read
/// and the node selected when the read completes. /// and the node selected when the read completes.
/// </summary> /// </summary>
private void EnsureTreeShows(ControlLocatedEventArgs e) /// <summary>
/// 返回 true 表示"已经开始读取另一个窗口的控件树",此时状态栏是它的提示,调用方不要再覆盖。
/// </summary>
private bool EnsureTreeShows(ControlLocatedEventArgs e)
{ {
if (e.Node == null || e.AnchorWindow == IntPtr.Zero) if (e.Node == null || e.AnchorWindow == IntPtr.Zero)
{ {
return; return false;
} }
if (FindTreeNode(_controlTree.Nodes, e.Node) != null) if (FindTreeNode(_controlTree.Nodes, e.Node) != null)
{ {
return; return false;
} }
if (e.AnchorWindow == _treeRootHandle) if (e.AnchorWindow == _treeRootHandle)
{ {
// Same window, different source/content: re-reading would not help. // Same window, different source/content: re-reading would not help.
return; return false;
} }
NativeWindowInfo window = _windowService.Capture(e.AnchorWindow); NativeWindowInfo window = _windowService.Capture(e.AnchorWindow);
if (window == null) if (window == null)
{ {
return; return false;
} }
_pendingTreeSelection = e.Node; _pendingTreeSelection = e.Node;
SetStatus("该控件属于另一个窗口(" + window + "),正在读取它的控件树……", null); SetStatus("该控件属于另一个窗口(" + window + "),正在读取它的控件树……", null);
BeginTreeRead(e.AnchorWindow, null, window, "定位监控项"); BeginTreeRead(e.AnchorWindow, null, window, "定位监控项");
return true;
} }
/// <summary> /// <summary>
@@ -3507,11 +3524,11 @@ namespace pacs_win_uia
return false; return false;
} }
// Minimized or covered windows get no frame: a box over something the operator cannot see // 最小化/被别的程序挡住的窗口不画框(框在看不见的地方只会添乱)。本工具自己的窗口
// only adds noise. Our own overlay is ignored by the check. // (主界面、设置窗口、各种覆盖层)不算遮挡,否则在工具里定位时永远画不出框。
string visibilityReason; string visibilityReason;
if (!WindowVisibility.IsVisibleOnScreen( if (!WindowVisibility.IsVisibleOnScreen(
e.AnchorWindow, rect, Process.GetCurrentProcess().Id, out visibilityReason)) e.AnchorWindow, rect, Process.GetCurrentProcess().Id, true, out visibilityReason))
{ {
reason = "不画框(" + visibilityReason + "):等目标显示出来再定位。"; reason = "不画框(" + visibilityReason + "):等目标显示出来再定位。";
return false; return false;