获取最小化窗口的大小

获取最小化窗口的大小

本文介绍了获取最小化窗口的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从来不知道这一点,但显然:

I never knew this, but apparently:

默认情况下,系统会减少一个最小化窗口到其大小任务栏按钮并移动最小化任务栏的窗口.一个恢复窗口是一个窗口恢复到原来的大小和位置,即它的大小在最小化或最大化之前.

在应用程序中,我们想在退出时保存各种窗口的位置/大小.这会导致最小化窗口出现问题.我们的解决方案是在运行保存状态逻辑之前恢复所有窗口,但这似乎很糟糕.有没有更好的办法?

In an application, we want to save the position/size of various windows at exit. This leads to a problem for minimized windows. Our solution is to restore all windows before running the save-state logic, but that just seems hacky. Is there a better way?

推荐答案

如何使用 GetWindowPlacement?这将返回一个 WINDOWPLACEMENT 结构,其中包含有关窗口坐标的信息恢复的位置.

How about using GetWindowPlacement?That returns a WINDOWPLACEMENT structure that contains information about the window's coordinates in the restored position.

请记住(正如 Leo Davidson 在评论中指出的那样)您必须尊重工作区坐标和屏幕坐标之间的差异.正如 WINDOWPLACEMENT 文档所解释的:

Remember that (as Leo Davidson points out in the comments) that you must respect the difference between workspace and screen coordinates. As the WINDOWPLACEMENT documentation explains:

中使用的坐标WINDOWPLACEMENT 结构应该是仅由 GetWindowPlacement 使用和 SetWindowPlacement 函数.将工作区坐标传递给期望屏幕的功能坐标(如 SetWindowPos)将导致窗口出现在错误的位置.例如,如果任务栏位于顶部屏幕,保存窗口坐标使用 GetWindowPlacement 和恢复他们使用 SetWindowPos 导致窗口出现爬行"屏幕.

或者,我之前毫无疑问使用过的更简单的解决方案就是在保存状态之前检查窗口是否最小化,如果是,则跳过保存任何状态信息.

Or, the simpler solution that I've no doubt used before is just to check if the window is minimized before saving the state, and if it is, skip saving any state information.


至于解释为什么窗口在最小化时会改变其大小,Raymond Chen 的博客该主题的条目(以及链接条目)是必读的.它们并没有真正改变任务栏按钮的大小,而是改变为 160x31 的预定义大小.他解释说,您可以通过将 MDI 子窗口最小化到其父窗口来看到这一点——这就是它的大小.


As far as explaining why a window changes its size when it gets minimized, Raymond Chen's blog entry (and the linked entry as well) on the subject is mandatory reading. They don't really change to their taskbar button's size, but rather to a pre-defined size of 160x31. He explains that you can see this by minimizing a MDI child window into its parent—that's really its size.

这篇关于获取最小化窗口的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 08:28