Detecting Windows animation settings

2019-03-01 08:33发布

I'm working on a program that runs basic smoke tests and acceptance tests on Windows applications under development. Part of what it does is to snapshot the app's top-level window(s) when it(they) first appears. It does this by starting the process, waiting for input idle, enumerating top-level windows, and then getting the window DC and blitting from it.

It turns out that the first appearance of a top-level window is animated by default--it fades in and expands to its actual size--at least on Windows 7. Screenshots taking during the animation are either missing the window frame or the frame is scaled down and partially transparent.

Screenshot of a Hello-World app as the top-level window appearance animation is in progress

I can avoid this problem by adding a delay (e.g., Sleep(250)) before taking the screenshot, but I can't find any information on how long the animations may actually take. If the animation takes longer on a future version of Windows (or if it's user adjustable), this delay might not be long enough. If the animations are disabled, then I'm just wasting time. (The tool will be used to run many tests, so the quarter second delays could add up.)

I can avoid the problem by checking the "Turn off all unnecessary animations" checkbox in the Ease of Access Center control panel, which seems to disable this animation. I figured this might correspond to a setting (or settings) programmatically accessible via SystemParametersInfo. If I could check when the animation is enabled, I could add the delay only when needed. I could also consider disabling the animations for the duration of the tests and then restoring the user's choice afterwards.

But I can't seem to find the SPI setting that corresponds to this particular animation. There is SPI_GETANIMATION, which indicates whether minimize and restore animations are enabled. However, that setting is independent of setting for the top-level window appearance animation.

Is there an API to detect whether top-level window appearance animations are enabled? Is there a setting that controls the speed of them so my code knows how long to delay? Is there a signal my program can watch for to know when a window from a child process is fully painted and finished animating?

1条回答
小情绪 Triste *
2楼-- · 2019-03-01 09:24

The answer appears to be "no."

David Heffernan successfully identified this is the Desktop Window Manager transitions setting. Unfortunately, there doesn't seem to be an API to read this setting. You can use DwmSetWindowAttribute with DWMWA_TRANSITIONS_FORCEDISABLED to change it, but it's a global setting so that's not advisable. Likewise, the duration of the animation is not exposed.

If someone finds information to the contrary (or if an API is added in a newer version of Windows), please add an answer and I will accept it.

查看更多
登录 后发表回答