Can you have multiple animation managers in an application?

theLooch 1 Reputation point
2021-02-26T00:37:17.26+00:00

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 - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,511 questions
{count} votes

2 answers

Sort by: Most helpful
  1. theLooch 1 Reputation point
    2021-02-26T18:48:00.257+00:00

    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://learn.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.


  2. Castorix31 83,096 Reputation points
    2021-03-05T18:50:53.53+00:00

    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

    0 comments No comments