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;
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.
Adrian mccarthy
source share