question

theLooch-7370 avatar image
0 Votes"
theLooch-7370 asked ·

Can you have multiple animation managers in an application?

I've used the Windows animation API (UIAnimationManager) in a number of places in my code and it's always worked well. However, I now have a dialog where I have two custom controls and each of these controls has an animation manager that handles animation for the control. Each of these controls animates fine by itself, but when I try to animate both controls at once it fails. I'm getting inconsistent, weird results. The documentation seems to make it sound like the normal case is to have a single animation manager for an entire application. Instead, I have custom controls that create and initialize their own animation managers which are around for the life of the control. Is this my problem? Is it not possible to have more than one animation manager in an application running at the same time? If this is the case, then this makes the api a lot less useful for me, because it's nice to wrap a control with all it's animation up into one class that can be used anywhere. It would really complicate things if I have to modify any applications that use my controls to provide an animation manager. Anyone know for sure if this is my problem? Thanks!

windows-api-general
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello, @theLooch-7370

but when I try to animate both controls at once it fails. I'm getting inconsistent, weird results.

Can you add more details?

  • Will there be an error message when it fails?

  • Will there be an API returning an error?

  • What does the weird results mean?

    The documentation seems to make it sound like the normal case is to have a single animation manager for an entire application.

Can you share the link to this document so that we can check it?

If it is convenient, please post some code so that we can reproduce your problem.





0 Votes 0 ·
theLooch-7370 avatar image
0 Votes"
theLooch-7370 answered ·

This might be a simpler explanation. I have 2 custom controls that are derived from CWnd. Each of them creates it's own private animation manager, variables, storyboards, etc. so that it can animate it's drawing. All of the animation API code is inside the control, and it works. However, when I do this it doesn't work:

Control1 ctrl1;
Control2 ctrl2;
ctrl1.Animate();
ctrl2.Animate();

In this case I now have 2 animation managers animating at once, even though nothing is shared between them. The result is that usually one of the controls animates fine and the other one doesn't. The one that doesn't work will have no painting notifications, or maybe just one and it seems like the animation variable values are wrong when it does. The results are inconsistent, so it seems like the timing of things is important. It seems like the 2 separate animation managers don't like animating at the same time. I get no errors or bad return codes from any functions.

I'll also point out that I have cases where I have multiple classes that each have their own animation managers that exist simultaneously, and they all work fine. The problem only happens when more than one of these is actually animating at the same time.

https://docs.microsoft.com/en-us/windows/win32/uianimation/scenic-animation-api-overview
This page says, "A single animation manager object typically manages all animations across an application and therefore has global control over all scheduled storyboards." The word "typically" there makes it sound like this is what most users would do, but does it mean that an application can only have one animation manager period? Is having multiple animation managers in a single application not allowed? If so, this will make it much harder for me to use this API.

· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You can try to create a thread and put the second animation manager in a new thread. The new thread needs its own message loop to avoid the first animation manager from occupying the main thread's message loop all the time.

You could write an app that had more than one UI thread in it - and each thread that creates windows would then need its own message loop

Refer: How does the message loop use threads?



0 Votes 0 ·
Castorix31 avatar image
0 Votes"
Castorix31 answered ·

I did some tests with a Custom Control and the problem seems to be from IUIAnimationTimerEventHandler
When I use it, I have the same problem you described : only 1 control receives Paint events
When I use my own Timer, all the controls receive Paint events

Test with 2 Custom Controls where I just change gradient colors with a IUIAnimationVariable variable, with and without IUIAnimationTimerEventHandler =>


With IUIAnimationTimerEventHandler : 1st Custom control does not receive Paint events :
74778-uianimation.gif


With a classic Timer : the 2 Custom Controls reveive Paint events:
74951-uianimation2.gif






uianimation.gif (1.7 MiB)
uianimation2.gif (1.7 MiB)
·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.