Virtual Developer Workshop: Containerized Development with Docker


This simple class is for people who want to make their dialog based application more attractive, using icon animation in the title bar.


All the consecutive images used for animation are stored in a single bitmap resource. The animation could have been achieved also by storing each image as separate icon in the resource, but that would have made managing them more difficult. Putting the images as a list of image also makes it easier to keep track of the sequence of animation.

To start with the class loads the bitmap resource in a CImageList using CimageList::Create function. Then whenever ShowNextImage is called the class loads the image using CimageList::ExtractIcon and displays it in title bar by calling CWnd::SetIcon for the application's main dialog.


1. Add AnimateDlgIcon.cpp and AnimateDlgIcon.h files in your project.

2. Create a bitmap resource and put all the images (16 pixels x 16 pixels) in the desired sequence.

3. Add #include "AnimateDlgIcon.h" at the beginning of the header file of your main dialog class.

4. Add the following protected members to your main dialog class

    CAnimateDlgIcon m_animIcon;
    UINT m_timerID;
5. Add the following code in InitInstance of your main Dialog class
    m_timerID = this->SetTimer(99,500,NULL);
SetImageList takes 3 parameters pass ID of your bitmap resource created in step 2 as first parameter. The second parameter is the no of (16x16) images in your bitmap, which is 4 in our case. The last parameter is the RGB value of color you want to make transparent. Second line of code sets a new timer. Here I have made it to fire every 500 ms. you can change it to suit your animation speed.

6. Create a OnDestroy() handler for your main dialog class and add the following code. This is very important because if you do not kill the timer created you will lose system resources.

    if(m_timerID != 0)

7. Add WM_TIMER handler to your frame class and add the following code


Compile and run the code. Now you should be able to see your window icon being animated. Note that just adding the above code also would bring up default MFC icon for a moment. If you want to avoid this change the IDR_MAINFRAME icon in the resource.


The sample project is built using Visual C++ 4.1, and has been tested on Visual C++ versions 4.1 and 6.0. If you directly try to run the .exe in the sample project it may ask for VC 4.1 runtime DLLs.

Download demo project - 32 KB

Download source - 2 KB


  • Animated busy dialog

    Posted by Legacy on 10/23/2003 07:00am

    Originally posted by: con99


    I am looking for a way to write a busy dialog in java (something like the windows copy dialog) ~ any suggestions?

  • i'd like to hide the title bar without loose its name at start bar

    Posted by Legacy on 05/23/2003 07:00am

    Originally posted by: jorge

    i'd like to hide the title bar of my application without loose its name at start windows bar. Someone knows the way?

  • Can we add GIF's in the title bar...?

    Posted by Legacy on 09/08/2002 07:00am

    Originally posted by: Vivek Anand

    It is interesting to add an animated icon (not actual) on the title bar.

    But I want to add a GIF's on the title bar.

    If anybody finds some code, then please help me.

  • Help needed!!

    Posted by Legacy on 10/30/2001 08:00am

    Originally posted by: vivek dabral


    I know that this form is intended for the feedback but i still need a help.
    I am new to VC++ & i have to insert images on button,radio button,edit box,label,title bar& close button at the top right corner of dialog.
    I also need to show different images on the mouse over events.
    Please help me.This is urgent too...

    Thanx & Regards
    Vivek Dabral

  • How to add this animation to 2nd dialog box

    Posted by Legacy on 11/17/2000 08:00am

    Originally posted by: XiaoCong

    Good !! Now i want to add this animation to 2 dialog box which come after the main dialog box, how?

  • good! thanks alot

    Posted by Legacy on 10/26/2000 07:00am

    Originally posted by: Harok

    it will be helpful to me thanks

  • How to attach larger/longer icon on title bar?

    Posted by Legacy on 05/10/2000 07:00am

    Originally posted by: Jessie Shoo

    First of all, thanks for the sample code coz it's really a usefull piece. But, i was just wondering how to attach a larger or longer icon on the title bar where the default space providing was limitted to 16x16 sizes. Thanks.

  • 256 colors support?

    Posted by Legacy on 01/03/2000 08:00am

    Originally posted by: Zhen Li

    It is a very example. But it did not support 256 color ICON.

  • Animated Icon

    Posted by Legacy on 11/10/1999 08:00am

    Originally posted by: Salomon Moyal Bloch

    Dear Rajesh Parikh,

    Merci.Thanx. Excellent work.Grazie mile.Toda raba.Danke.

    I used it for a status bar reporting the actual status
    of a spectrophotometer connection.


    I'll try to send my own code based on this superb class ASAP.
    1. Change: Circles are much nicer.(we could discuss about it
    for hours..)
    2. Change: The status bar is more adequate for that kind of visual 'status' report.

  • How to Add Status Bar to the CDialog

    Posted by Legacy on 06/15/1999 07:00am

    Originally posted by: Kevin Cao

    anybody out there known how to add a status bar to the CDialog ?

    I really need your help.


  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date