Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
896 views
in Technique[技术] by (71.8m points)

winapi - Detecting Windows animation settings

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...