简体   繁体   English

如何获得 window 的航空快照 state?

[英]How to get the aero snap state of a window?

When a window is resized by aero snap, User32.GetWindowPlacement(hWnd).rcNormalPosition still stores its original rectangle, while User32.GetWindowRect is affected.当 window 通过 aero snap 调整大小时,User32.GetWindowPlacement(hWnd).rcNormalPosition 仍然存储其原始矩形,而 User32.GetWindowRect 受到影响。
Since aero snap seems independent from WINDOWPLACEMENT, now we cannot collect the complete information of the actual placement simply using user32.dll.由于 aero snap 似乎独立于 WINDOWPLACEMENT,现在我们无法仅使用 user32.dll 收集实际放置的完整信息。 Thus I'm wondering if there's a way to get the aero snap state of a window, indicating whether the window is docked and which side the window is docked to .因此,我想知道是否有办法获取 window 的 aero snap state,指示window 是否已停靠以及window 停靠在哪一侧

Aero Snap is a feature of the Shell, not the windowing system. Aero Snap 是 Shell 的功能,而不是窗口系统。 Thus, the windowing system cannot provide that information, because it is not aware of those states.因此,窗口系统无法提供该信息,因为它不知道这些状态。

And the Shell doesn't make this information available either. Shell 也不提供此信息。 So, in essence, the system doesn't provide the Aero Snap state of any given window through a public API.因此,从本质上讲,系统不会通过公共 API 提供任何给定 window 的 Aero Snap state。

I like having my main windows remember all of their placement information so that I it can be restored when they are restarted.我喜欢让我的主 windows 记住它们的所有位置信息,以便在它们重新启动时可以恢复。 In that past, it was enough to save a copy of the window placement structure and to set it back when recreating the window.在过去,保存 window 布局结构的副本并在重新创建 window 时将其设置回去就足够了。

The introduction of snap required keeping some extra information.引入 snap 需要保留一些额外的信息。 I detected whether a window appeared to be snapped by comparing its window rectangle to the work area rectangle of the monitor that contains the window. If it seemed to be snapped to one of the edges, I recorded that along with the placement information.我通过将其 window 矩形与包含 window 的监视器的工作区矩形进行比较来检测 window 是否似乎被捕捉。如果它似乎被捕捉到其中一个边缘,我将其与放置信息一起记录下来。 Upon creating the window, I first restore the window placement, and then, if I have a snap state recorded, I change the window's size and position accordingly.创建 window 后,我首先恢复 window 位置,然后,如果我记录了快照 state,我会相应地更改窗口大小和 position。

You can distinguish between a window that's been snapped to a monitor edge from one that's been carefully sized and placed there because the snapped window's rectangle won't match the one in the window placement.您可以区分已捕捉到监视器边缘的 window 与经过仔细调整大小并放置在那里的 window,因为捕捉窗口的矩形与 window 放置中的矩形不匹配。

This approach worked great in Windows 7. I recently discovered that Windows 10 added more flexibility to the snap locations and sizes as well as playing more games to achieve the annoyingly invisible resize borders.这种方法在 Windows 7 中非常有效。我最近发现 Windows 10 为捕捉位置和大小增加了更多灵活性,并玩了更多游戏以实现令人讨厌的隐形调整边框。 So my detection code doesn't always recognize a snapped window, but that should fixable.所以我的检测代码并不总能识别出 window,但这应该是可以修复的。

Some popular software (like the major browsers) seem to remember that they were snapped, and I assume they use the same approach.一些流行的软件(如主流浏览器)似乎记得它们被抓拍过,我假设它们使用相同的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM