且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

GetWindowPlacement给出不正确的窗口位置

更新时间:2021-10-20 01:25:00

AeroSnap只是另一种类型的调整大小发送到您的应用程序的窗口经理。因此,你不知道它是快照,而不是任何其他类型的调整大小。

AeroSnap is just another type of resize sent to your app by the window manager. As such you don't get to know that it was snap rather than any other type of resize.

你***的希望是检测到相反的边缘在大小事件的过程中移动。您需要检查高度或宽度是否已更改为与移动事件相区别。

The best you can hope for is to detect that opposite edges have been moved in the course of a size event. You'd need to check that height or width changed to so as to distinguish it from a move event.

为什么你不知道这是一个快照的原因是很难想象为什么一个应用程序会关心调整大小的机制。

The reason why you don't get told that this is a snap is that it's hard to imagine why an app would care what the mechanism for resizing is.

这些评论更多地揭示了你的问题。您正在尝试在应用程序关闭时保持您的应用程序位置和大小,以便您可以在重新启动时恢复它。您正在使用 GetWindowPlacement()这样做,并发现它返回一个不正确的位置,当窗口的最后一个尺寸是Aero Snap。

The comments have revealed more about your problem. You are trying to persist your apps position and size when the app closes down so that you can restore it when it restarts. You are using GetWindowPlacement() to do so and have discovered that it returns an incorrect position when the last sizing of the Window was an Aero Snap.

我自己的应用程序完全一样,我遇到了完全相同的问题。我使用的解决方案是调用 GetWindowRect()代替 GetWindowPlacement()获得窗口位置和大小。你说这对你失败,在这种情况下,我不知道建议什么。我必须说,我发现有点难以相信, GetWindowRect()不返回正确的窗口rect。

My own app does exactly the same and I have encountered the exact same problem. The solution I used was to call GetWindowRect() in place of GetWindowPlacement() to obtain the window position and size. You state that this fails for you, in which case I have no idea what to suggest. I must say I find it a little hard to believe that GetWindowRect() does not return the correct window rect.