Click here to Skip to main content
Email Password   helpLost your password?
  • Download demo project - 24 Kb
  • Download source files - 5 Kb

    animated screen shot

    Introduction

    Often in modern GUI you can see a some sort of window or menu animation that can give a more user friendly "cool" look. Fading or sliding menus, poping dialog boxes look neat and provide visual feedback with user actions. Currently, however there is no simple way to do this under MS Windows, other than XORed lines and polygons (besides the AnimateWindow() function).

    The AnimEffect class provides quite an easy and extensible way to add animation to your code.

    Usage

    Using the class is rather simple. Just add the following code to the dialogs OnCreate and OnDestroy functions.

     AnimEffect ef;
     // exploding window effect
    
     ef.Open( rcWnd );
     // or imploding window effect
    
     ef.Close( rcWnd );
    

    You can customize the effect by calling the Setup( int iSteps, int iAfterimages, int iDelay ) member function, and change the animation type by Effect( EffectType effect ), where EffectType is :

       enum EffectType {
         Random=-1,       // default
    
         Spin=0,          
         Vortex,
         ScatterGather,
         Spike,
         Fireworks
       };
    

    Included is a simple demo project that shows a bunch of effects. Feel free to use this code.

  • You must Sign In to use this message board.
     
     
    Per page   
     FirstPrevNext
    GeneralIt won't work with Vista Aero
    julio.debroy
    14:19 16 Oct '07  
    This code is great, but sad to say it wont work under vista if aero theme is activated, and need to change (programmatically) to vista basic theme for it to work.
    GeneralGreat code
    El Chapulin Colorado
    2:17 3 May '07  
    I have been coding a MasterMind game where you have to guess the colors combination choosen by the computer, which gives you information about the answer via black and white figures.

    I had to find a nice and funny way to display a message when the user finally finds the answer, and to make him happy for winning the game. So I decided to use your animated dialog for this, and many people who played the MasterMind game noticed it and found it very pleasant and nice.

    So I have to congratulate you for this simple and smart idea, and let you know that your code is being used and greatly appreciated.

    Thank you again !
    GeneralSIMPLY
    Hugo.Pereira
    2:25 21 Dec '06  
    GOOD
    GeneralHats off
    Balkrishna Talele
    23:41 11 Dec '03  
    Amazing, enchanting, truly the creativity is divine inside and out, You made me unspoken . I lull before you imagination.
    GeneralI bow before thy creativity
    abhinaba
    19:42 10 Dec '03  
    Amazing!!!! Just do not have words to praise your creativity. All the code you have used are simple yet the effect is incredible OMG

    ==========================
    AB => Code and let code
    Go to my home ==========================
    GeneralAmazing!
    T.S. Prasad
    19:04 21 Apr '03  
    When I thought everything in GUI development is over, this article came as a bolt from blue. Hence I give highest possible rating.

    T.S. Prasad
    GeneralI finally found this class!
    iProgram (WangYue)
    0:26 13 Jan '03  
    It takes our Chinese guys a long time to guess how to make this awesome effect. Thanks Anton. Great job.Eek!
    GeneralThis is soooo cooool !!
    WREY
    0:21 28 Sep '02  
    It shows that you have the power of creativity!!

    Simply great!

    Cool

    William
    GeneralOnly one little note...
    AV
    22:34 9 Oct '00  
    void AnimEffect::ChooseFunc()
    {
    bool bRandom = false;

    if (m_Effect == Random) {

    srand(time(NULL));<--------------- //TO DO THIS.

    bRandom = true;
    Effect((EffectType)(rand() % 5));
    }
    .........
    GeneralRe: Only one little note...
    Joephia
    7:33 1 Sep '08  
    AnimEffect::AnimEffect()
    {
    m_hDC = ::GetDC(NULL);
    m_hPen = ::CreatePen( PS_SOLID, 1, RGB(0,0,0) );
    srand(time(NULL));
    Defaults();
    }
    Generalset position od adialog ?
    Khoa Vinh
    18:16 10 Aug '00  
    I need to set the init position of a dialog .
    It was a chirld of CDialog Class??
    My Project use VC++ Wizar
    Generalset position od adialog ?
    Khoa Vinh
    18:15 10 Aug '00  
    I need to set the position od dialog.
    It was a chirld of CDialog Class??
    My Project use VC++ Wizar
    GeneralSpeed
    George
    8:37 6 May '00  
    I am using this class with great success. The only problem I noticed is the speed - on PII200 it is slow, but acceptable. But on PIII500 it is too fast, I think PIII800 would make it way too fast..
    GeneralRe: Speed
    tiaozi
    3:02 25 May '02  
    my pc is CII733+128m... speed is well.

    i test it in P4-1.6G/256M DDR, speed is not very fast than image! ACCEPTALE!

    I'm a chinese boy...
    I like vb/vc++...
    GeneralRe: Speed
    xiangjs
    7:01 27 Feb '03  
    you can modify m_iDelay.
    such as m_iDelay=10;
    GeneralAwesome!
    Duc Truong
    15:03 26 Apr '00  
    I added this effect to my About dialog this morning and I've been clicking on the About... choice on the popup menu all day.

    I didn't want to "dirty" codetools with another pure "thank you" comment, but I couldn't help myself.

    My About dialog would surely has your name on it. It's an honor to do so!

    A million thanks,

    Generalwhen ondestroy, leaves lines behind
    Martin
    19:59 18 Apr '00  
    How can I change the code so that when it is done it updates the window behind the effect.
    Depending on the effect most of the lines are left behind (any windows that lie behind need to be updated).

    Also, my OnCreate function will always display the animation the correct size but at 0,0:

    int CAdevtest2Dlg::OnCreate(LPCREATESTRUCT lpcs)
    {
    if (CDialog::OnCreate(lpcs) == -1)
    return -1;

    // exploding window effect
    // CRect rc(lpcs->x,lpcs->y,lpcs->x+lpcs->cx,lpcs->y+lpcs->cy); // This does not work either
    CRect rc;
    GetWindowRect( rc );
    AnimEffect ef;
    ef.Effect(AnimEffect::Spike);
    ef.Open( rc );

    return 0;
    }


    GeneralRe: when ondestroy, leaves lines behind
    flight
    12:41 19 Apr '00  
    I had the same time with ON_DESTROY, so I added a Sleep(100) and it works like a charm
    GeneralRe: when ondestroy, leaves lines behind
    George
    9:37 29 Apr '00  
    >Also, my OnCreate function will always display the
    >animation the correct size but at 0,0:

    Put the code into OnShowWindow (WM_SHOWWINDOW).

    Good Luck!
    GeneralRe: when ondestroy, leaves lines behind
    Simon Brown
    1:10 12 May '00  
    I also have this problem, and am going to try to resolve it. My method of attack will be to send a repaint message (or whatever) to all toplevel windows.

    I have the code to do this somewhere, once I do it I'll post it here.

    Simo
    GeneralRe: when ondestroy, leaves lines behind
    FuMo
    15:00 12 Jun '00  
    RedrawWindow(GetDesktopWindow(),NULL,NULL,RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN |RDW_ERASENOW)
    GeneralRe: when ondestroy, leaves lines behind
    Rainer Koschnick
    13:34 5 Sep '00  
    ::RedrawWindow(GetDesktopWindow()->m_hWnd, NULL,NULL,RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN |RDW_ERASENOW);
    General:)
    Alex Turc
    9:31 18 Apr '00  
    Small code, great idea
    Generalsystem hook????
    LJP
    6:01 18 Apr '00  
    It would be cool to be able to hook this into the system, and use it for the default window min/max/close effects...
    way RAD, man
    GeneralRe: system hook????
    Chris Maunder
    13:52 18 Apr '00  
    LOL!

    you'd make your users dizzy :


    Last Updated 18 Apr 2000 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010