GetWindowPlacement给出不正确的窗口位置 [英] GetWindowPlacement gives the incorrect window position

查看:384
本文介绍了GetWindowPlacement给出不正确的窗口位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 Aero Snap功能了解窗口是否已调整大小? GetWindowPlacement 函数给出最新的恢复窗口大小。我使用它如下:

How to find out whether a window was resized using Aero Snap feature? GetWindowPlacement function gives the latest "restored" window size. I use it as follows:

WINDOWPLACEMENT wp = {};
wp.length = sizeof(WINDOWPLACEMENT);
::GetWindowPlacement( hWnd, &wp );

例如,它给出 wp.rcNormalPosition = {top = 208 bottom = 520 left = 152 right = 510} ,应为
{top = 0 bottom = 1920 left = 152 right = 510} >。

For instance, it gives wp.rcNormalPosition = {top=208 bottom=520 left=152 right=510}, when it should be {top=0 bottom=1920 left=152 right=510}.

请注意, GetWindowRect 提供完全相同的不正确结果。是我的错, GetWindowRect 给出正确的结果。

Please, note that GetWindowRect gives exactly the same incorrect result. That was my fault, GetWindowRect gives the right result.

我需要保存窗口状态在程序退出和加载它在开始,所以我需要知道如何窗口放置。我如何找到实际的窗口坐标?

I need to save window state on the program exit and load it on start, so I need to know how windows are placed. How can I find out actual window coordinates?

好吧,我用记事本做了几个测试。 exe (和一些其他标准的Windows组件),它以相同的方式保存它的状态—它不记得是否是捕捉。所以我想这是Windows程序的行为。

Well, I made several tests with notepad.exe(and some other standard Windows components) and it saves its state in the same way — it doesn't remember whether it was "snapped". So I suppose this is intended behavior of Windows programs.

推荐答案

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.

这篇关于GetWindowPlacement给出不正确的窗口位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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