UIAutomation 元素在远程桌面连接上为边界矩形返回错误值
UIAutomation Element returning wrong values for Bounding Rectangle on Remote Desktop Connection
问题陈述是我们所需的应用程序将 运行 在远程计算机上,我们用户将通过远程桌面连接使用该计算机。这个想法是只截取应用程序区域的屏幕截图,运行在那台机器上。我们能够通过 spyxx 获得应用程序 window 矩形边界,window 句柄对于 window 返回正确并且 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 Aware 是针对每个显示器的。在这种情况下,正确的边界矩形是左侧 65、顶部 10、右侧 1793 和底部 1020,但我得到的边界矩形 105、568、1108,594 是错误的。
@Jimi 完全正确。我得到了一些错误的 window 措施,但来自相同的过程和相同的 window 句柄。它通过使用这个 var railWindow = AutomationElement.RootElement.FindFirst(TreeScope.Children, new AndCondition(new[] { new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window), new PropertyCondition(AutomationElement.ClassNameProperty, "RAIL_WINDOW")}));
对我有用
问题陈述是我们所需的应用程序将 运行 在远程计算机上,我们用户将通过远程桌面连接使用该计算机。这个想法是只截取应用程序区域的屏幕截图,运行在那台机器上。我们能够通过 spyxx 获得应用程序 window 矩形边界,window 句柄对于 window 返回正确并且 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 Aware 是针对每个显示器的。在这种情况下,正确的边界矩形是左侧 65、顶部 10、右侧 1793 和底部 1020,但我得到的边界矩形 105、568、1108,594 是错误的。
@Jimi 完全正确。我得到了一些错误的 window 措施,但来自相同的过程和相同的 window 句柄。它通过使用这个 var railWindow = AutomationElement.RootElement.FindFirst(TreeScope.Children, new AndCondition(new[] { new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window), new PropertyCondition(AutomationElement.ClassNameProperty, "RAIL_WINDOW")}));