使用SetWindowPlacement更改窗口的还原位置并非在每个窗口上都有效 [英] Changing a window's restore position using SetWindowPlacement doesn't work on every window

查看:475
本文介绍了使用SetWindowPlacement更改窗口的还原位置并非在每个窗口上都有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SetWindowPlacement 函数,以(1)最大化和(2)更改桌面上外部窗口的还原位置.但是,当我在WinForm窗口上使用此命令时,似乎无法正确设置还原位置. (我正在测试的WinForm窗口只是一个未经修改就运行的VS2008 WinForms应用程序.)因此,例如,如果该窗口处于(0,0)的还原状态,并且我使用SetWindowPlacement将其最大化,并且将其还原位置设置为(100,100),然后单击窗口的还原按钮,它将不还原为(100,100),而是还原为(0,0).实际上,好像该窗口首先还原到我设置的位置,然后在以编程方式进行操作之前移回其最后的还原位置.我对为什么仅在WinForm窗口上会发生这种情况感到困惑-我尝试使用的每个非WinForm窗口都能正确还原到我用SetWindowPlacement指示的位置.

I'm using the SetWindowPlacement function to (1) maximize and (2) change the restore position of external windows on the desktop. But when I use this command on WinForm windows, it doesn't seem to set the restore location correctly. (The WinForm window I'm testing with is just a VS2008 WinForms application run without modification.) So, for example, if the window is in a restored state located at (0, 0) and I use SetWindowPlacement to maximize it and set its restore position to (100,100), then click the window's restore button, it will restore not to (100,100) but to (0,0). It actually seems like the window first restores to the location I set, THEN moves back to its last restore location prior to being manipulated programmatically. I'm confused as to why this would happen only on WinForm windows - every non-WinForm window I try this on restores correctly to the position I indicated with SetWindowPlacement.

我知道这没什么大不了的,但是我想知道这里的人是否对为什么会这样有任何想法.谢谢.

I know that's not much to go on, but I was wondering if anyone here had any ideas about why this is happening. Thanks.

推荐答案

是的,这是设计使然. Form类会跟踪还原界限本身,这是必需的,因此它可以在重新创建窗口之后正确地重新放置窗口. Windows窗体经常动态地重新创建窗口,以实现只能由CreateWindowEx()指定的属性的属性设置器.就像ShowInTaskbar.

Yes, this is by design. The Form class keeps track of the restore bounds itself, necessary so it can properly reposition the window after it was re-created. Windows Forms often recreates the window on-the-fly to implement property setters for properties that can only be specified by CreateWindowEx(). Like ShowInTaskbar.

专用的RestoreWindowBoundsIfNecessary()方法将窗口放回原位,它将在还原窗口时运行.据我所知,在窗口最小化或最大化之前就锁定了恢复范围.如果要在最小/最大化窗口的同时修改还原位置,则必须使用MoveWindow将其移动到要还原窗口后 的位置.应该会产生闪烁.

The private RestoreWindowBoundsIfNecessary() method puts the window back, it will run when the window is restored. From what I can tell, the restore bounds are latched just before the window is minimized or maximized. If you want to modify the restore position while the window is min/maximized then you'll have to use MoveWindow to move it where you want it to go after restoring the window. Ought to produce some flicker.

这篇关于使用SetWindowPlacement更改窗口的还原位置并非在每个窗口上都有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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