何时(以及如何)布局 Win32 窗口的子窗口以响应调整大小? [英] When (and how) to lay out the children of a Win32 window in response to a resize?

查看:16
本文介绍了何时(以及如何)布局 Win32 窗口的子窗口以响应调整大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当调整窗口大小时,Windows 会发送几条消息:

Windows sends several messages when a window is resized:

  • WM_GETMINMAXINFO
  • WM_ENTERSIZEMOVE
  • WM_EXITSIZEMOVE
  • WM_NCCALCSIZE
  • WM_SIZE
  • WM_SIZE
  • WM_WINDOWPOSCHANGING
  • WM_WINDOWPOSCHANGED

可能还有更多.

如果我想在调整窗口大小时重新定位孩子,在哪里以及如何我应该这样做?
我正在寻找最佳"方法——即问题最少且闪烁最少的方法.

If I would like to re-position the children when my window is resized, where and how should I do so?
I'm looking for the "best" method -- i.e. the method with the fewest gotcha's and the least flicker.

我的当前方法是使用DeferWindowPosWM_NCCALCSIZE内执行所有重新定位.
但是,我也尝试在 WM_WINDOWPOSCHANGED 内部处理它...但无论我在哪里处理它,似乎总是至少有一个 当窗口在中间状态下绘制时的时刻",其中窗口的大小已更改,但其内容尚未调整大小.

My current method is to perform all the repositioning inside WM_NCCALCSIZE, using DeferWindowPos.
However, I've also tried handling it inside WM_WINDOWPOSCHANGED... but no matter where I handle it, it seems like there is always at least one "moment" when the window is painted in an in-between state, where the window's size has changed, but its contents have yet to be resized.

另一个我想要避免的效果:在孩子已经移动之后移动.由于我的更改,我不希望用户看到控件向下滑动然后返回——它应该具有尽可能少的瞬态效果.

Another effect I would also like to avoid: moving a child after it has already moved. I don't want the user to see a control sliding down and then back up because of my change -- it should have as few transient effects as possible.

我这样做正确吗?有没有更好的地方可以让我布置窗户的孩子?

Am I doing this correctly? Is there a better place I can lay out the window's children?

推荐答案

您应该在 WM_SIZE 消息中重新定位窗口,因为这是窗口在完成其任务之前收到的最后一个...重新定位可以使用 MoveWindow 的窗口

You should re-position the window in the WM_SIZE message, because that is the last one that the window recieves before complete it's task...To re-position the window you can use MoveWindow

这篇关于何时(以及如何)布局 Win32 窗口的子窗口以响应调整大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆