简体   繁体   English

如何在Windows中最大化的窗口上无缝调用MoveWindow?

[英]How do I seamlessly call MoveWindow on a maximized window in Windows?

I have a C# application that is attempting to create a customizable version of Windows's Snap functionality. 我有一个C#应用程序正在尝试创建Windows Snap功能的可自定义版本。 I primarily use the native functions MoveWindow and ShowWindowAsync . 我主要使用本机函数MoveWindowShowWindowAsync I also use GetWindowPlacement to determine maximized/normal/minimized state. 我还使用GetWindowPlacement确定最大化/正常/最小化状态。

I can seamlessly snap a "normal" window around to my user definable frames. 我可以无缝地将“常规”窗口捕捉到用户可定义的框架上。 The window instantly snaps to new desired position and size. 窗口立即捕捉到新的所需位置和大小。

The problem is when I transition from maximized to normal. 问题是当我从最大化过渡到正常时。 If I only call MoveWindow then the window snaps to my desired position and size. 如果我仅调用MoveWindow,则窗口将捕捉到我想要的位置和大小。 However the window still thinks it's "maximized" which causes attempts to re-maximize to fail. 但是,窗口仍然认为它是“最大化”的,这会导致尝试重新最大化失败。

However if I call ShowWindowAsync(wnd, SW_SHOWNORMAL) followed by MoveWindow(wnd, x, y, width, height, true) it causes the maximized window to animate to it's old position then snap to its new position. 但是,如果我先调用ShowWindowAsync(wnd, SW_SHOWNORMAL)然后再调用MoveWindow(wnd, x, y, width, height, true) ShowWindowAsync(wnd, SW_SHOWNORMAL) MoveWindow(wnd, x, y, width, height, true)它将使最大化的窗口动画化为其旧位置,然后捕捉到其新位置。 This is very jarring and unpleasant. 这是非常刺耳和令人不快的。 Attempting to flip the call order or use ShowWindow instead of ShowWindowAsync does not help. 尝试翻转呼叫顺序或使用ShowWindow而不是ShowWindowAsync没有帮助。

The answer to this question might be to disable the animation. 该问题的答案可能是禁用动画。 I have not found a clean way to do that. 我还没有找到一种干净的方法。

Solution found! 找到解决方案!

The fix is to call SetWindowPlacement instead of MoveWindow . 解决方法是调用SetWindowPlacement而不是MoveWindow SetWindowPlacement takes a WINDOWPLACEMENT structure which allows setting both position/size and showCmd state at the same time. SetWindowPlacement采用WINDOWPLACEMENT结构,该结构允许同时设置位置/大小和showCmd状态。

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

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