Click here to Skip to main content
13,300,002 members (56,193 online)
Click here to Skip to main content
Add your own
alternative version


20 bookmarked
Posted 27 Jul 2000

CXWndAnimate: an alternative to CAnimateCtrl

, 27 Jul 2000
Rate this:
Please Sign up or sign in to vote.
An animation control that uses a bitmap imagelist instead of an AVI file
<!-- Download Links -->
  • Download demo project - 24 Kb
  • <!-- Article image -->

    Sample Image - cxwndAnimate.jpg

    <!-- Main HTML starts here -->


    Recently I had to develop an processing indicator to show to the user that my application is doing some heavy calculations or retrieving lots of data from a database.

    My first thought was about using the CAnimateCtrl. I must confess i tried, but without success. I couldn't make an AVI file with transparent background (maybe I'm too lazy). So I decided to develop my own Animate Control using bitmaps through an image list.

    For each control of this I have a thread to constantly update the animation.

    How to use

    1. Call the static method RegisterWnd on the InitInstance of your CWinApp derived class
    2. In dialogs: you have to place a custom control a give it the class name "X_WND_ANIMATE". Next you declare an CXWndAnimate member variable on your dialog class. On the OnInitDialog you have to subclass the control:
      m_ctrlAnimation.SubclassDlgItem(IDC_ANIMATION, this);
    3. In Status Bar you have to create it on a pane. Also remember to correct the control's position when the StatusBar is resized.
      BOOL CMyStatusBar::CreateAnimation(int iIndex)
      	CFrameWnd* pFrame = reinterpret_cast<CFRAMEWND*> (GetParent());
      	m_pwndBmpAnimate = new CWndBmpAnimate;
      	CRect rcItem;
      	GetItemRect(iIndex, &rcItem);
      	rcItem.right = rcItem.left + CX_ANIMATION;
      	rcItem.InflateRect(-1, -1);
      	BOOL bReturn = m_pwndBmpAnimate->Create(WND_BMP_ANIMATE, 
      			NULL, WS_CHILD | WS_VISIBLE, rcItem, this, 0);
      	return bReturn;
      void CMyStatusBar::OnSize(UINT nType, int cx, int cy) 
      	CStatusBar::OnSize(nType, cx, cy);
      	// TODO: Add your message handler code here
      	if (m_pwndBmpAnimate)
      		CRect rcItem;
      		GetItemRect(CommandToIndex(ID_ANIMATED), &rcItem);
      		rcItem.right =  rcItem.left + CX_ANIMATION; 
      		rcItem.InflateRect(-1, -1);
      		m_pwndBmpAnimate->SetWindowPos(NULL, rcItem.left,, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
    4. To select the animation you must construct bitmaps files with the frames for the animation (like an animated gif). To set the images that are going to be used, do this:
      CImageList imgList;
      imgList.Create(IDB_BITMAP, 14, 0, RGB(255, 255, 255));

      In this case the white color will be the transparent color. Each frame has 14 pixels width. If your animation need a total redrawing (redraw the background) make sure to call the method SetClearBackground.

    The sample project demonstrates the use of the control in a dialog box.

    Other relevants methods:

    • BOOL IsRunning(): indicates if the animation is playing
    • BOOL StartAnimation(short nStart, short nEnd = -1): Starts to play an animation. If nEnd if -1 the animation will play until it's end
    • BOOL StopAnimation(BOOL bHideWindow = TRUE): Stops the animation and hide the window if bHideWindow is equal TRUE


    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    About the Author

    Architect VisionOne AG
    Switzerland Switzerland
    XicoLoko is a brazilian developer based in Switzerland.

    You may also be interested in...

    Comments and Discussions

    GeneralStart in OnInit Pin
    Anonymous5-Nov-02 6:14
    sussAnonymous5-Nov-02 6:14 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    Permalink | Advertise | Privacy | Terms of Use | Mobile
    Web01 | 2.8.171207.1 | Last Updated 28 Jul 2000
    Article Copyright 2000 by xicoloko
    Everything else Copyright © CodeProject, 1999-2017
    Layout: fixed | fluid