【发布时间】:2017-12-27 22:38:33
【问题描述】:
当我使用 ClientToScreen() 时,我得到了客户端窗口的坐标,但它不包括文件菜单栏。当一个窗口有一个文件菜单栏时,这对我来说只是一个问题,例如Windows 计算器。
public Point createPoint(IntPtr handle)
{
Point myPoint = new Point(0, 0);
Point myPointClient = new Point(0, 0);
RECT myRectWindow;
if (radioButtonEntireWindow.Checked) // Green cross
{
// Result: (0, 0)
}
else if (radioButtonClientWindowFileMenu.Checked) // Red cross
{
// This works for windows 7, but probably not for windows 10:
myPoint = new Point(8, 30);
// Result: (8, 30)
}
else if (radioButtonClientWindow.Checked) // Purple cross
{
GetWindowRect(handle, out myRectWindow);
ClientToScreen(handle, ref myPointClient);
myPoint = new Point(myPointClient.X - myRectWindow.Location.X, myPointClient.Y - myRectWindow.Location.Y);
// Result: (8, 50)
}
return myPoint;
}
如何在不明确使用 (8, 30) 的情况下获得红十字坐标?使用 GetWindowRect() 和 GetClientRect() 获取标题栏高度不起作用,因为它不包含文件菜单栏,就像 ClientToScreen() 一样。
【问题讨论】:
-
使用本机窗口菜单的应用程序在菜单栏下方开始其客户区。菜单本身位于非客户区。例如,有些做,有些不做,比较 Winforms MainMenu 控件与 MenuStrip。 GetMenu() 将返回一个非空菜单句柄,GetMenuBarInfo() 返回它的大小。
-
@HansPassant 我没有使用winforms。我正在寻找这样做,例如Chrome 或 windows 计算器
-
只是一个例子,这就是我推荐winapi函数的原因。
-
你想完成什么?听起来像是一个问题,答案是 UI 自动化。
-
@IInspectable 我正在尝试使用例如文件菜单栏截取客户端窗口区域或客户端窗口区域的屏幕截图。 windows计算器