Virtual Developer Workshop: Containerized Development with Docker


This simple class is for people who want to make their application more attractive using icon animation in the title bar of frame window.


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 sending WM_SETICON to the frame window.


1. Add AnimateIcon.cpp and AnimateIcon.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 "AnimateIcon.h" at the beginning of your mainframe.h file.

4. Add the following protected members to your mainframe class

    CAnimateIcon m_animIcon;
    UINT m_timerID;
5. Add the following code in OnCreate member of your frame 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 frame 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_TIMERhandler 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.

This version also fixes resources problem reported by few users.

Download demo project - 46 KB

Download source - 2 KB

Date Updated: December 2, 1998


  • Thanks

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

    Originally posted by: Code Guy


    Thanks for the handy code. It's nice to be able to add a little flair to otherwise drab loooking applications with something like this icon animator.

    -Code Guy

  • How to display a text with owner fonts

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

    Originally posted by: Bui

    I don't know How to display a text with owner fonts in
    title bar . Please help me , Thank you very much

  • Ref: Request for tech help on VB++

    Posted by Legacy on 06/13/2001 07:00am

    Originally posted by: Shuvro

    I want to Manipulate a Image File which is Scanned from the newspaper Page.
    Image size is in Pixel: Width:-2440

    I have developed a Browser with Vb6 using Picture Box Control.
    I have kept all options like Zooming in , Zooming Out and Cropping a selected Portion.
    Sometimes it works and Sometimes it Fails.When it fails it shows an error Message.
    When I make the picture bigger than its Original size and also try to Crop a Selected Part it shows error.Error message is : AutoRedraw cannot Create Image.Err Number is 480
    But I have to work with big Image.

  • Quick way to make imagelists...

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

    Originally posted by: Mark Stevens

    A real easy way to manage the bitmaps in an imagelist is to use a toolbar resource. It is actually stored as two separate resources, a regular bitmap resource and a toolbar resource. the nice thing is you can move buttons around and edit/resizing is a piece of cake.

    In your code you just use the toolbar's resource ID as a bitmap and ignore the other part.

  • You can use this with CDialog

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

    Originally posted by: Sergey

    Just change the original line:
    HICON hPrevIcon = (HICON)AfxGetMainWnd()->SendMessage(WM_SETICON,TRUE,(LPARAM)hIcon);

    HICON hPrevIcon = (HICON)AfxGetMainWnd()->SetIcon(hIcon, FALSE);


  • Nice Code It is But.................

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

    Originally posted by: Nauman Ahmad Khan

    Very simple code is written to animate an icon on the title bar but one problem is there that how to keep all images in the same bitmap resource is not more clear. One way in my mind is that you create an image which holds the small images ( they should be explicitly created ) and include this image as bitmap resource. Thanks and congratulations on such a simple to use code 

  • How about stop the timer.

    Posted by Legacy on 03/08/1999 08:00am

    Originally posted by: Yuan Songjun

    I have setup an application as what you have shown.
    It works. There is a ever-changing icon in the application's title bar.
    While I want to stop it from the CView derived class, so I call it by ((CFramWnd*) GetParentFrame()->OnDestroy();
    It does not work: the icon is still changina as ever.
    How to stop it from outside?

  • Nice Code

    Posted by Legacy on 02/23/1999 08:00am

    Originally posted by: Thomas Gathercoal

    Fun idea. Might I suggest adding menu items to allow the user to disable
    the animation and/or change the frame rate.

  • 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