Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimize/restore windows programmatically skipping the animation effect

I need to perform several operations on a list of windows (minimize some of them, restore others) in order to switch between two or more set of windows at once.

The problem with this are those animations you can see when minimizing and restoring a window. The whole process look terrible with all those animations going in and out, up and down.
I cannot, however, disable those animations because this is for other computers and i dont want to change other people's settings, plus those animations are actually useful when you minimize/restore one window only (i.e. when YOU do it manually) because you can see what is happening, but for doing it programmatically on several windows at a time, it's not nice.

I'm currenlty using the SendMessage function to send the WM_SYSCOMMAND message with params SC_MINIMIZE/SC_RESTORE. I dont know whether there is another way.

So, the question:
How can I minimize/restore a window programatically without the animation effect??

PS: The programming language is not important. I can use any language that's nessesary for accomplishing this.

like image 681
GetFree Avatar asked May 21 '11 00:05

GetFree


3 Answers

SetWindowPlacement with SW_SHOWMINIMIZED or SW_RESTORE as appropriate for showCmd in WINDOWPLACEMENT seems to bypass window animation. I'd keep an eye on the functionality for future versions of the OS though since documentation does not mention anything about animation.

like image 154
Sertac Akyuz Avatar answered Oct 21 '22 05:10

Sertac Akyuz


How about Hide > Minimize > Show ?

like image 30
NGLN Avatar answered Oct 21 '22 05:10

NGLN


You could temporarily disable the animations and then restore the user's original setting.

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 constructed, it remembers the user's original setting and turns off the animation. The destructor restores the original settings. By using a c'tor/d'tor, you ensure that the user's settings are restored if your rearranging code throws an exception.

There is a small window of vulnerability here. In theory, the user could change the setting during the operation, and then you'll slam the original setting back. That's extremely rare and not really that bad.

like image 34
Adrian McCarthy Avatar answered Oct 21 '22 04:10

Adrian McCarthy