如何获取 "free" of child windows 的客户区矩形
How to get rectangle of the client area that is "free" of child windows
是否有 API 或一些众所周知的程序来获取没有 child windows 的客户端矩形?
例如,下面给出的示例 window 我想要得到带有红框的矩形:
感谢有用的评论让我找到了 wikipedia definition 边界框,我想出了以下函数来计算最小边界框:
此函数将只计算子控件占用的父 window 矩形,要获得未占用的区域,结果矩形需要根据入口客户区矩形偏移,这取决于控件的哪一部分window 我们想要(所以它被排除在这个答案之外)
注意: 在此示例中,mChilds
变量是子控件和 windows 的 std::list
容器,以及 mhWnd
是包含子控件的父 window 的句柄。
D2D1_RECT_F ParentWindow::CalculateBoundingBox() const noexcept
{
RECT client;
D2D1_RECT_F result{ };
GetClientRect(mhWnd, &client);
if (mChilds.empty())
{
result = {
.left = static_cast<float>(client.left),
.top = static_cast<float>(client.top),
.right = static_cast<float>(client.right),
.bottom = static_cast<float>(client.bottom),
};
return result;
}
RECT window;
GetWindowRect(mhWnd, &window);
// Inverse of the parent screen coordinates
std::swap(window.left, window.right);
std::swap(window.top, window.bottom);
for (auto& child : mChilds)
{
RECT rc;
GetWindowRect(child->GetHandle(), &rc);
window.left = std::min(rc.left, window.left);
window.top = std::min(rc.top, window.top);
window.right = std::max(rc.right, window.right);
window.bottom = std::max(rc.bottom, window.bottom);
}
POINT lt{
.x = window.left,
.y = window.top
};
POINT br{
.x = window.right,
.y = window.bottom
};
ScreenToClient(mhWnd, <);
ScreenToClient(mhWnd, &br);
result = {
.left = static_cast<float>(lt.x),
.top = static_cast<float>(lt.y),
.right = static_cast<float>(br.x),
.bottom = static_cast<float>(br.y),
};
return result;
}
是否有 API 或一些众所周知的程序来获取没有 child windows 的客户端矩形?
例如,下面给出的示例 window 我想要得到带有红框的矩形:
感谢有用的评论让我找到了 wikipedia definition 边界框,我想出了以下函数来计算最小边界框:
此函数将只计算子控件占用的父 window 矩形,要获得未占用的区域,结果矩形需要根据入口客户区矩形偏移,这取决于控件的哪一部分window 我们想要(所以它被排除在这个答案之外)
注意: 在此示例中,mChilds
变量是子控件和 windows 的 std::list
容器,以及 mhWnd
是包含子控件的父 window 的句柄。
D2D1_RECT_F ParentWindow::CalculateBoundingBox() const noexcept
{
RECT client;
D2D1_RECT_F result{ };
GetClientRect(mhWnd, &client);
if (mChilds.empty())
{
result = {
.left = static_cast<float>(client.left),
.top = static_cast<float>(client.top),
.right = static_cast<float>(client.right),
.bottom = static_cast<float>(client.bottom),
};
return result;
}
RECT window;
GetWindowRect(mhWnd, &window);
// Inverse of the parent screen coordinates
std::swap(window.left, window.right);
std::swap(window.top, window.bottom);
for (auto& child : mChilds)
{
RECT rc;
GetWindowRect(child->GetHandle(), &rc);
window.left = std::min(rc.left, window.left);
window.top = std::min(rc.top, window.top);
window.right = std::max(rc.right, window.right);
window.bottom = std::max(rc.bottom, window.bottom);
}
POINT lt{
.x = window.left,
.y = window.top
};
POINT br{
.x = window.right,
.y = window.bottom
};
ScreenToClient(mhWnd, <);
ScreenToClient(mhWnd, &br);
result = {
.left = static_cast<float>(lt.x),
.top = static_cast<float>(lt.y),
.right = static_cast<float>(br.x),
.bottom = static_cast<float>(br.y),
};
return result;
}