微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

UIAutomation 元素在远程桌面连接上返回错误的边界矩形值

如何解决UIAutomation 元素在远程桌面连接上返回错误的边界矩形值

问题陈述是我们所需的应用程序将在我们用户将通过远程桌面连接使用该机器的远程机器上运行。这个想法是只对在该机器上运行的应用程序区域进行截图。我们能够通过 spyxx 获取应用程序窗口矩形边界,窗口句柄返回正确的窗口并且 processId 是可访问的,但是当我们尝试获取矩形边界时,我们得到了一些错误的坐标。任何帮助将不胜感激。

var winhandle = NativeMethods.FindWindow("RAIL_WINDOW",null);
            if (winhandle != IntPtr.Zero)
            {
                var mainEMRWindow = AutomationElement.FromHandle(winhandle);
                if (mainEMRWindow != null)
                {
                   Console.WriteLine("Bounding Rectangle: " + mainEMRWindow.Current.BoundingRectangle.Left + "," + mainEMRWindow.Current.BoundingRectangle.Top + "," + mainEMRWindow.Current.BoundingRectangle.Right + "," + mainEMRWindow.Current.BoundingRectangle.Bottom);
                                           RECT clientRect = GetClientRect(winhandle);

                    Console.WriteLine("Client Rect: " + "Left: " + clientRect.Left.ToString() + "," + "Top: " + clientRect.Top.ToString() + "," + "Right: " + clientRect.Right.ToString() + "," + "Bottom: " + clientRect.Bottom.ToString());

                    Rectangle rc;
                    GetwindowRect(winhandle,out rc);

                    Console.WriteLine("Window Rect: " + "Left: " + rc.Left.ToString() + "," + "Top: " + rc.Top.ToString() + "," + "Right: " + rc.Right.ToString() + "," + "Bottom: " + rc.Bottom.ToString());
                }
            }

我还要附上应用程序和代码的屏幕截图。 DPI 感知是每个监视器。在这种情况下,正确的边界矩形是左 65、前 10、右 1793 和下 1020,但我得到的是错误的边界矩形 105、568、1108,594。

enter image description here

enter image description here

解决方法

@Jimi 是绝对正确的。我得到了一些错误的窗口度量,但是来自相同的过程和相同的窗口句柄。使用此 var railWindow = AutomationElement.RootElement.FindFirst(TreeScope.Children,new AndCondition(new[] { new PropertyCondition(AutomationElement.ControlTypeProperty,ControlType.Window),new PropertyCondition(AutomationElement.ClassNameProperty,"RAIL_WINDOW")}));

对我有用

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。