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;