::MoveWindow 的问题 - 留下空白

发布于 2024-12-09 04:26:10 字数 611 浏览 1 评论 0原文

我非常渴望解决这个非常烦人的问题:( 我正在尝试在父窗口上显示子窗口。有时需要调整窗口大小。但由于某种原因,当我使用 MoveWindow 函数时,它会在父窗口顶部留下空白区域。我想在这里展示一张图片,但我无法发布图片。

这是代码示例:

HWND hwnd  // Comes from external function. Was defined as WS_CHILD previously
HWND hwndParent     = ::GetParent(hwnd);  
RECT parentRect     = {0,0,0,0};  
RECT childRect      = {0,0,0,0};  
::GetClientRect(hwndParent, &parentRect);  // Suppose it returns {0,0,600,300}  

BOOL ok = ::MoveWindow(hwnd, 0, 0, 600, 300, true);  
::GetClientRect(hwnd, &childRect);  // Will return {0,0,584,297}  

为什么???

我做错了什么?我是否忘记了窗口初始化的一些标志?!

I am quite desperate to resolve this very annoying issue :(
I am trying to display a child window on parent window. Some time the window need to be resized. But for some reason, when I using MoveWindow function it leaves blank space on the top of the parent window. I would like to present a picture here but I can not post a picture.

Here is the code example:

HWND hwnd  // Comes from external function. Was defined as WS_CHILD previously
HWND hwndParent     = ::GetParent(hwnd);  
RECT parentRect     = {0,0,0,0};  
RECT childRect      = {0,0,0,0};  
::GetClientRect(hwndParent, &parentRect);  // Suppose it returns {0,0,600,300}  

BOOL ok = ::MoveWindow(hwnd, 0, 0, 600, 300, true);  
::GetClientRect(hwnd, &childRect);  // Will return {0,0,584,297}  

WHY ?????

What am I doing wrong? Did I forgot some flags with window initialization?!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一身仙ぐ女味 2024-12-16 04:26:10

不使用 GetClientRect,而是使用 GetWindowRectMapWindowPoints(NULL,hwndParent,&parentRect,2) 将其调整为父窗口坐标。 GetWindowRect 将包含 MoveWindow 所需的非客户区。

编辑:如果您想要一个没有非客户区域的窗口,因此窗口矩形和客户矩形大小相同,则需要修剪 应用到窗口的窗口样式。避免使用 WS_BORDER、WS_CAPTION、WS_DLGFRAME、WS_OVERLAPPED、WS_SIZEBOX 和 WS_THICKFRAME 样式。

Rather than use GetClientRect, use GetWindowRect and MapWindowPoints(NULL,hwndParent,&parentRect,2) to adjust it to the parent window coordinates. GetWindowRect will include the non-client area that MoveWindow requires.

Edit: If you want a window that doesn't have a non-client area so the window rect and the client rect are the same size, you need to trim the window styles that you apply to the window. Avoid the WS_BORDER, WS_CAPTION, WS_DLGFRAME, WS_OVERLAPPED, WS_SIZEBOX, and WS_THICKFRAME styles.

甜宝宝 2024-12-16 04:26:10

MoveWindow 更新窗口位置,而 GetClientRect 获取窗口的客户区部分,两者不必相同。如果您的窗口有非客户区,那么一切都很好并且按预期工作。

如果您仍然认为子窗口没有完全覆盖父窗口的客户区域,那么间距属于子控件/窗口,您需要寻找将其删除的方法(控制标志、参数等)。

MoveWindow updates window position, while GetClientRect gets a client-area part of the window, which does not have to be the same. If your window has non-client area, then everything is fine and works as expected.

If you are still under impression that child window does not fully cover parent's client area, then the spacing belongs to the child control/window, and you need to look for ways to remove it there (control flags, parameters etc).

少女净妖师 2024-12-16 04:26:10

MoveWindow 对窗口坐标进行操作——包括非客户区域(边框、标题栏等)。

GetClientRect 获取窗口客户端部分的区域,忽略边框、标题栏等。

这就是不匹配的地方。如果您想要MoveWindow到所需的客户端大小,您只需AdjustWindowRect 尝试预测要传递的内容移动窗口。请注意,这并不总是可能的,而且并不总是准确的。例如窗口、菜单(可以换行至多行)等的最小/最大尺寸。

MoveWindow operates on window coordinates -- including non-client area (borders, title bar, etc).

GetClientRect gets the area of the client portion of the window, ignoring borders, title bar, etc.

This is where the mismatch is. If you want to MoveWindow to a desired client size, you need to just AdjustWindowRect to try and predict what to pass into MoveWindow. Note that it's not always possible, and not always accurate. For example minimum / maximum sizes of windows, menus (which can wrap to multiple lines), etc.

调妓 2024-12-16 04:26:10

问题是父窗口的 WS_POPUP 标志。
很奇怪。据我所知,它不应该有这样的效果。

谢谢大家!

The problem was WS_POPUP flag to the parent window.
Very strange. As far as I know it was not suppose to have such an effect.

Thanks for everyone!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文