{"id":111986,"date":"2026-01-14T07:00:00","date_gmt":"2026-01-14T15:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=111986"},"modified":"2026-01-14T08:05:57","modified_gmt":"2026-01-14T16:05:57","slug":"20260114-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20260114-00\/?p=111986","title":{"rendered":"Clipping the focus item when looking for its on-screen location, part 3"},"content":{"rendered":"<p>Last time, <a title=\"Clipping the focus item when looking for its on-screen location, part 2\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20260113-00\/?p=111984\"> we clipped the focus item to the accessible parent<\/a> so that we considered only the visible portion of the item. But we found that this failed to clip some items, such as items in File Explorer. What&#8217;s going on?<\/p>\n<p>The reason is that the parent of the clipped item is a wrapper and not the Tiles view container. We really need to intersect the item with parent elements all the way up the tree to get it fully clipped.<\/p>\n<pre>bool SetCursorPosToLocation(IAccessible* acc, LONG childId)\r\n{\r\n    RECT rcObject;\r\n    if (GetAccessibleBounds(acc, childId, &amp;rcObject)) {\r\n        RECT rcParent;\r\n        if (childId != CHILDID_SELF) {\r\n            if (GetAccessibleBounds(acc, CHILDID_SELF, &amp;rcParent)) {\r\n                IntersectRect(&amp;rcObject, &amp;rcObject, &amp;rcParent);\r\n            }\r\n        } else {\r\n            <span style=\"border: solid 1px currentcolor;\">wil::com_ptr_nothrow&lt;IAccessible&gt; accParent(acc);<\/span>\r\n            wil::com_ptr_nothrow&lt;IDispatch&gt; dispParent;\r\n            <span style=\"border: solid 1px currentcolor;\">while<\/span> (<span style=\"border: solid 1px currentcolor;\">accParent<\/span>-&gt;get_accParent(dispParent.put()) == S_OK &amp;&amp;\r\n                dispParent) {\r\n                <span style=\"border: dashed 1px currentcolor;\"><span style=\"text-decoration: line-through;\">\/* auto *\/<\/span><\/span> accParent = dispParent.try_query&lt;IAccessible&gt;();\r\n                if (accParent &amp;&amp;\r\n                    GetAccessibleBounds(accParent.get(), CHILDID_SELF,\r\n                                        &amp;rcParent)) {\r\n                    IntersectRect(&amp;rcObject, &amp;rcObject, &amp;rcParent);\r\n                }\r\n            }\r\n        }\r\n        SetCursorPos(rcObject.right - 1, rcObject.bottom - 1);\r\n        return true;\r\n    }\r\n    return false;\r\n}\r\n<\/pre>\n<p>I&#8217;m going to stop here because this seems to work reasonably well, except of course for the programs I noted earlier that simply refuse to report the caret position at all. I&#8217;m not sure what to do about those guys.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Finding <I>all<\/I> the clipping parents.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-111986","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Finding <I>all<\/I> the clipping parents.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111986","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=111986"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111986\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=111986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=111986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=111986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}