From 695b98dd351b9c9f1678fbd3f0a40e3ce3aebb54 Mon Sep 17 00:00:00 2001 From: zimoyin <2556608754@qq.com> Date: Tue, 13 Oct 2026 16:10:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=91=E6=8E=A7=E5=88=97=E8=A1=A8=E5=AE=9A?= =?UTF-8?q?=E4=BD=8D=E5=90=8E=E5=BF=85=E7=84=B6=E8=81=94=E5=8A=A8=E6=8E=A7?= =?UTF-8?q?=E4=BB=B6=E6=A0=91=EF=BC=8C=E5=B9=B6=E6=8A=8A=E6=9C=AC=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E7=AA=97=E5=8F=A3=E6=8E=92=E9=99=A4=E5=87=BA=E5=AE=9A?= =?UTF-8?q?=E4=BD=8D=E6=A1=86=E9=81=AE=E6=8C=A1=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户反馈:在控件监控列表里定位显示已定位到「control」,但控件树不展开也不选中。 根因:MonitorEditorOnControlLocated 在画不出高亮框时直接 return,跳过了 SelectTreeNodeFor/EnsureTreeShows;而画不出框的常见原因就是本工具自己的窗口 压在目标上(CanShowLocateFrame 用的是严格可见性)。 - 定位成功一律先展开并选中控件树节点,画框与否只影响高亮框 - 画不出框时状态栏说明原因,但不再吞掉树联动 - HighlightFollower/CanShowLocateFrame 与本工具悬浮条统一规则:本工具自身 窗口不算遮挡,只有别的程序挡住目标才隐藏定位框 - EnsureTreeShows 返回已去读另一个窗口的树,避免状态栏提示被覆盖 - 实测(进程内宿主+镜像树模拟解析器返回的另一实例):定位后树中选中该节点、 祖先展开、切到控件树页、Path 横条同步;无矩形时同样选中 - 回归测试 23/23 通过 Co-Authored-By: Claude Code --- docs/XPath定位.md | 2 +- .../Services/HighlightFollower.cs | 4 +- src/pacs_win_uia/UI/MainForm.cs | 49 +++++++++++++------ 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/docs/XPath定位.md b/docs/XPath定位.md index ad85308..e0e8867 100644 --- a/docs/XPath定位.md +++ b/docs/XPath定位.md @@ -320,7 +320,7 @@ RuntimeId 和 HWND 适合当前运行中的重新绑定,不适合直接作为 ### 直接编辑 -在“控件监控列表”中: +在“控件监控列表”中,点击任意一行(或“定位到控件”按钮)都会:先在屏幕上高亮该控件,**同时在控件树里展开祖先并选中该节点**,控件树下方的 Path 横条也会同步显示它的 XPath。即使当前画不出高亮框(目标最小化、被别的程序遮住、或控件没有矩形),控件树的联动照样发生。 1. 选中 `控件Path` 单元格; 2. 按 `F2` 或直接输入; diff --git a/src/pacs_win_uia/Services/HighlightFollower.cs b/src/pacs_win_uia/Services/HighlightFollower.cs index f7bb7bf..cc4b736 100644 --- a/src/pacs_win_uia/Services/HighlightFollower.cs +++ b/src/pacs_win_uia/Services/HighlightFollower.cs @@ -233,7 +233,9 @@ namespace pacs_win_uia.Services } 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 // comes back when the operator can see the target again. The reason is reported once. diff --git a/src/pacs_win_uia/UI/MainForm.cs b/src/pacs_win_uia/UI/MainForm.cs index ba64c35..4f1d7a3 100644 --- a/src/pacs_win_uia/UI/MainForm.cs +++ b/src/pacs_win_uia/UI/MainForm.cs @@ -3300,7 +3300,14 @@ namespace pacs_win_uia string 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; } @@ -3311,14 +3318,20 @@ namespace pacs_win_uia e.AnchorWindow, BuildBoundsResolver(e.Definition, e.Node), "定位框"); - SetStatus(e.UsedFallback + // 定位成功就一定有联动:在控件树里展开祖先并选中该节点(与"能不能画框"无关)。 + // 若节点属于另一个窗口,则改为去读那个窗口的树,读完再选中(它的提示优先)。 + bool selected = SelectTreeNodeFor(e.Node); + if (EnsureTreeShows(e)) + { + return; + } + + SetStatus((e.UsedFallback ? "已高亮该控件(" + e.Bounds + "),但这次是用容错规则定位的,框的位置可能不准:" - + "建议在界面里重新添加该控件;再点一次行头可隐藏。" - : "已在屏幕上高亮该控件(" + e.Bounds + ");再点一次行头可隐藏。", null); - // Selecting the node may find the tree belongs to another window, in which case that - // window's tree is read and this message is replaced by the more specific one. - SelectTreeNodeFor(e.Node); - EnsureTreeShows(e); + + "建议在界面里重新添加该控件。" + : "已在屏幕上高亮该控件(" + e.Bounds + ")。") + + (selected ? "控件树已展开并选中。" : "控件树里没有对应节点(可切换控件树来源或重读窗口)。") + + "再点一次行头可隐藏。", null); } /// @@ -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 /// and the node selected when the read completes. /// - private void EnsureTreeShows(ControlLocatedEventArgs e) + /// + /// 返回 true 表示"已经开始读取另一个窗口的控件树",此时状态栏是它的提示,调用方不要再覆盖。 + /// + private bool EnsureTreeShows(ControlLocatedEventArgs e) { if (e.Node == null || e.AnchorWindow == IntPtr.Zero) { - return; + return false; } if (FindTreeNode(_controlTree.Nodes, e.Node) != null) { - return; + return false; } if (e.AnchorWindow == _treeRootHandle) { // Same window, different source/content: re-reading would not help. - return; + return false; } NativeWindowInfo window = _windowService.Capture(e.AnchorWindow); if (window == null) { - return; + return false; } _pendingTreeSelection = e.Node; SetStatus("该控件属于另一个窗口(" + window + "),正在读取它的控件树……", null); BeginTreeRead(e.AnchorWindow, null, window, "定位监控项"); + return true; } /// @@ -3507,11 +3524,11 @@ namespace pacs_win_uia 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; if (!WindowVisibility.IsVisibleOnScreen( - e.AnchorWindow, rect, Process.GetCurrentProcess().Id, out visibilityReason)) + e.AnchorWindow, rect, Process.GetCurrentProcess().Id, true, out visibilityReason)) { reason = "不画框(" + visibilityReason + "):等目标显示出来再定位。"; return false;