以编程方式最小化/恢复窗口,跳过动画效果

发布于 2024-11-08 10:52:17 字数 472 浏览 0 评论 0原文

我需要对窗口列表执行多项操作(最小化其中一些,恢复其他),以便立即在两组或多组窗口之间切换。

这样做的问题是最小化和恢复窗口时可以看到的动画。整个过程看起来很糟糕,所有这些动画都进进出出、上下移动。
但是,我无法禁用这些动画,因为这是针对其他计算机的,我不想更改其他人的设置,而且当您仅最小化/恢复一个窗口时(即当您手动执行此操作时),这些动画实际上很有用,因为您可以看到正在发生什么,但是对于一次在多个窗口上以编程方式执行此操作,这并不好。

我当前正在使用 SendMessage 函数发送带有参数 SC_MINIMIZE/SC_RESTOREWM_SYSCOMMAND 消息。不知道还有没有别的办法。

所以,问题是:
如何在没有动画效果的情况下以编程方式最小化/恢复窗口?

PS:编程语言并不重要。我可以使用完成此任务所需的任何语言。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

白馒头 2024-11-15 10:52:17

SetWindowPlacementSW_SHOWMINIMIZEDSW_RESTORE 适合 WINDOWPLACement 似乎绕过了窗口动画。我会密切关注操作系统未来版本的功能,因为文档没有提及任何有关动画的内容。

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.

画骨成沙 2024-11-15 10:52:17

您可以暂时禁用动画,然后恢复用户的原始设置。

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 ...
}

构造抑制器时,它会记住用户的原始设置并关闭动画。析构函数恢复原始设置。通过使用 c'tor/d'tor,您可以确保在重新排列代码引发异常时恢复用户的设置。

这里有一个小的漏洞窗口。理论上,用户可以在操作过程中更改设置,然后你就会把原来的设置恢复回来。这种情况非常罕见,而且也没有那么糟糕。

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.

亣腦蒛氧 2024-11-15 10:52:17

隐藏怎么样>最小化>展示 ?

How about Hide > Minimize > Show ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文