Minimize / restore windows by skipping animation effect

I need to perform several operations on the list of windows (to minimize some of them, restore others) in order to immediately switch between two or more sets of windows.

The problem with this is the animations that you can see when minimizing and restoring the window. The whole process looks awful when all these animations go and go, up and down.
However, I cannot turn off these animations, because it is for other computers, and I do not want to change the settings of other people, plus these animations are really useful when you minimize / restore only one window (i.e. when YOU do it manually), because you can see what is happening, but in order to do this programmatically across multiple windows at a time, this is not nice.

I use the SendMessage function to send a WM_SYSCOMMAND with the SC_MINIMIZE / SC_RESTORE . I do not know if there is another way.

So the question is:
How can I minimize / restore a window programmatically without an animation effect?

PS: The programming language is not important. I can use any language necessary to accomplish this.

+7
source share
3 answers

SetWindowPlacement with SW_SHOWMINIMIZED or SW_RESTORE according to showCmd in WINDOWPLACEMENT seems to get around the window animation. I will follow the functionality for future versions of the OS, though, since the documentation says nothing about animation.

+5
source

What about Hide> Minimize> Show?

+2
source

You can temporarily disable the animation, and then restore the user’s original settings.

 class WindowsAnimationSuppressor { public: WindowsAnimationSuppressor() : m_suppressed(false) { m_original_settings.cbSize = sizeof(m_original_settings); if (::SystemParametersInfo(SPI_GETANIMATION, sizeof(m_original_settings), &m_original_settings, 0)) { ANIMATIONINFO no_animation = { sizeof(no_animation), 0 }; ::SystemParametersInfo(SPI_SETANIMATION, sizeof(no_animation), &no_animation, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE); m_suppressed = true; } } ~WindowsAnimationSuppressor() { if (m_suppressed) { ::SystemParametersInfo(SPI_SETANIMATION, sizeof(m_original_settings), &m_original_settings, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE); } } private: bool m_suppressed; ANIMATIONINFO m_original_settings; }; void RearrangeWindows() { WindowsAnimationSuppressor suppressor; // Rearrange the windows here ... } 

When the suppressor is designed, it remembers the user's initial setting and disables the animation. The destructor restores the original settings. Using c'tor / d'tor, you guarantee that user preferences will be restored if your reordering code throws an exception.

There is a small window of vulnerability. Theoretically, the user can change the setting during the operation, and then you delete the original setting. This is extremely rare and not so bad.

+2
source

All Articles