Animated Icon on Titlebar of a Dialog based Application

Introduction:

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

Technique:

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.

Usage:

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_animIcon.SetImageList(IDB_ANIM_IMGLIST,4,RGB(0,0,0));
    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)
        KillTimer(m_timerID);

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

    m_animIcon.ShowNextImage();

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.

Note:

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



Comments

  • Animated busy dialog

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

    Originally posted by: con99

    Hi,

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

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

    Posted by Legacy on 05/23/2003 12: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?

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

    Posted by Legacy on 09/08/2002 12: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.

    Reply
  • Help needed!!

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

    Originally posted by: vivek dabral

    Hi!!

    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

    Reply
  • How to add this animation to 2nd dialog box

    Posted by Legacy on 11/17/2000 12: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?

    Reply
  • good! thanks alot

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

    Originally posted by: Harok

    it will be helpful to me thanks

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

    Posted by Legacy on 05/10/2000 12: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.

    Reply
  • 256 colors support?

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

    Originally posted by: Zhen Li

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

    Reply
  • Animated Icon

    Posted by Legacy on 11/10/1999 12: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.
    Greetings.

    Sal.

    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.

    Reply
  • How to Add Status Bar to the CDialog

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

    Originally posted by: Kevin Cao

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

    I really need your help.

    Thanks
    KevinCao
    unicred.vinet.com

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • Webinar on September 23, 2014, 2 p.m. ET / 11 a.m. PT Mobile commerce presents an array of opportunities for any business -- from connecting with your customers through mobile apps to enriching operations with mobile enterprise solutions. Join guest speaker, Michael Facemire, Forrester Research, Inc. Principal Analyst, as he discusses the new demands of mobile engagement and how application program interfaces (APIs) play a crucial role. Check out this upcoming webinar to learn about the new set of …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds