When (and how) to lay out the children of a Win32 window in response to a resize?

筅森魡賤 提交于 2019-11-30 16:03:19

问题


Windows sends several messages when a window is resized:

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

and possibly more.

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.

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?


回答1:


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



来源:https://stackoverflow.com/questions/10873236/when-and-how-to-lay-out-the-children-of-a-win32-window-in-response-to-a-resize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!