如何使用 Windows API 以编程方式调整窗口大小和移动窗口?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/692742/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you programmatically resize and move windows with the Windows API?
提问by Daniel Silveira
How do you programmatically resize and move windows with Windows API?
如何使用 Windows API 以编程方式调整窗口大小和移动窗口?
The scenario is: I want to vertically tile two windows (80%/20% width proportions).
场景是:我想垂直平铺两个窗口(80%/20% 宽度比例)。
回答by mghie
For flicker-free, simultaneously positioning two (or more) windows, your best bet is to use BeginDeferWindowPos(), DeferWindowPos()and EndDeferWindowPos(). In your case, since you're moving two at the same time, this is your best bet.
对于无闪烁、同时定位两个(或更多)窗口,最好的办法是使用 BeginDeferWindowPos()、DeferWindowPos()和EndDeferWindowPos()。在您的情况下,由于您同时移动两个,这是您最好的选择。
Three older, simpler functions you might also consider are SetWindowPos(), MoveWindow()and AdjustWindowRectEx().
您可能还会考虑的三个较旧的、更简单的函数是SetWindowPos()、MoveWindow()和AdjustWindowRectEx()。
回答by Reed Copsey
Use SetWindowPos()in the Windows API.
在 Windows API 中使用SetWindowPos()。
Given a HWND, you can change the z-order, position (upper left), size, as well as numerous other flags (like showing or hiding, making it the active window or not, etc).
给定 HWND,您可以更改 z 顺序、位置(左上角)、大小以及许多其他标志(如显示或隐藏、使其成为活动窗口等)。
回答by JaredPar
You're looking for one of SetWindowPos, MoveWindowand AdjustWindowRectEx.
您正在寻找SetWindowPos、MoveWindow和AdjustWindowRectEx 之一。
Can you be more specific about the scenario so that we can recomend the most appropriate API?
您能否更具体地说明场景,以便我们推荐最合适的 API?
回答by Net Citizen
SetWindowPos or MoveWindow will accomplish this for you
SetWindowPos 或 MoveWindow 将为您完成此操作
回答by Net Citizen
Look up MoveWindowin your SDK documentation.
在您的 SDK 文档中查找MoveWindow。