c# - 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,这是错误的。
解决方案
@Jimi 绝对正确。我得到了一些错误的窗口度量,但来自相同的进程和相同的窗口句柄。通过使用它对我有用var railWindow = AutomationElement.RootElement.FindFirst(TreeScope.Children, new AndCondition(new[] { new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window), new PropertyCondition(AutomationElement.ClassNameProperty, "RAIL_WINDOW")}));
推荐阅读
- android - 我的应用程序抛出光标索引 outOfBounds 异常,请求大小为 1 的 -1
- python - 使用 discord.py 在 vc discord 中播放音频 - InvalidArgument:传递的通道必须是语音通道
- javascript - jQuery中的链接方法
- javascript - Loopback4 - 如何将文件上传到 POSTS 模型
- mysql - 在定义 ON DELETE RESTRICT 时,是否有任何方法可以在 adhoc 基础上使用查询来使用 ON DELETE CASCADE 功能?
- reactjs - 反应功能无法识别
- symfony - Symfony Form + EntityType Field + oTm > mTo < oTm 关系 = 保存时类型错误
- reactjs - 使用 simpleWebRTC 进行存储设置
- usb - C# WPF 在外部 USB 相机按钮上捕获图像
- dart - 使用 Dartson 进行 Json 序列化