简体   繁体   中英

UIAutomation Element returning wrong values for Bounding Rectangle on Remote Desktop Connection

The problem statement is our required application will be running on a remote machine we user will be using that machine via Remote Desktop Connection. The idea is to take screenshots of the application area only, running on that machine. We are able to get application window rectangular bounds via spyxx, window handle is returning correct for the window and processId is accessible but when we are trying to get rectangular bounds we are getting some wrong coordinates. Any help would be appreciated.

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());
                }
            }

I am going to attach the screenshot of the application and code as well. DPI Aware is Per Monitor. Correct Bounding Rectangle is Left 65, Top 10, Right 1793, and bottom 1020 in this case but I'm getting Bounding Rectangle 105, 568, 1108,594 which is wrong.

在此处输入图像描述

在此处输入图像描述

@Jimi was absolutely right. I was getting some wrong window measures but from same process and same window handle. It worked for me by using this var railWindow = AutomationElement.RootElement.FindFirst(TreeScope.Children, new AndCondition(new[] { new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window), new PropertyCondition(AutomationElement.ClassNameProperty, "RAIL_WINDOW")}));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM