CDialog using animated control

CAnimateDlg (located in AnimateDlg.h/cpp) is a simple class derived from CDialog in order to implement user designed animated control. The user of the class has to call SetAnimationProperties() method and to pass to it the ID of the static control that will use as an animation control, number of frames in the "movie", array of bitmap IDs in the application resource and the time-slice between frame (to set the animation speed).

Header File

#if !defined(AFX_ANIMATEDLG_H__64C0DD41_7BA0_11D1_8DC6_0000E8125FE5__INCLUDED_)
#define AFX_ANIMATEDLG_H__64C0DD41_7BA0_11D1_8DC6_0000E8125FE5__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// AnimateDlg.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CAnimateDlg dialog

class CAnimateDlg : public CDialog
{
// Construction
public:
	void StopAnimation();
	void StartAnimation();
	void SetAnimationProperties(UINT controlID,  BYTE nFrames, UINT *pImagesArray, UINT timeSliceBetweenFrames);
	CAnimateDlg();   // standard constructor
	~CAnimateDlg();

// Dialog Data
	//{{AFX_DATA(CAnimateDlg)
		// NOTE: the ClassWizard will add data members here
	//}}AFX_DATA


// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAnimateDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:

	// Generated message map functions
	//{{AFX_MSG(CAnimateDlg)
	afx_msg void OnTimer(UINT nIDEvent);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
private:
	CBitmap m_CurrentBmp;
	BYTE m_CurrentFrame;
	UINT m_TimeInterval;
	UINT* m_pFramesArray;
	BYTE m_nFrames;
	UINT m_TargetCtrl;
	BOOL m_bPlayingNow;
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_ANIMATEDLG_H__64C0DD41_7BA0_11D1_8DC6_0000E8125FE5__INCLUDED_)

CPP File

// AnimateDlg.cpp : implementation file
//

#include 
#include "AnimateDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAnimateDlg dialog


CAnimateDlg::CAnimateDlg()
{
	//{{AFX_DATA_INIT(CAnimateDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_TimeInterval = 0;
	m_pFramesArray = NULL;
	m_nFrames = 0;
	m_TargetCtrl = 0;
	m_CurrentFrame = 1;
}

CAnimateDlg::~CAnimateDlg()
{
	if (m_bPlayingNow)
		StopAnimation();
}


void CAnimateDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAnimateDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAnimateDlg, CDialog)
	//{{AFX_MSG_MAP(CAnimateDlg)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAnimateDlg message handlers

void CAnimateDlg::SetAnimationProperties(UINT controlID, BYTE nFrames, UINT * pImagesArray, UINT timeSliceBetweenFrames)
{
	m_TimeInterval = timeSliceBetweenFrames;
	m_pFramesArray = pImagesArray;
	m_nFrames = nFrames;
	m_TargetCtrl = controlID;	
	m_bPlayingNow = FALSE;
}

void CAnimateDlg::StartAnimation()
{
	if (!m_bPlayingNow)
		SetTimer(0, m_TimeInterval, NULL);
}

void CAnimateDlg::StopAnimation()
{
	if (m_bPlayingNow)
		KillTimer(0);
}

void CAnimateDlg::OnTimer(UINT nIDEvent) 
{
	if (m_CurrentFrame > m_nFrames)
		m_CurrentFrame = 1;

	CStatic *pTargetCtrl = (CStatic *) GetDlgItem(m_TargetCtrl);
	ASSERT(pTargetCtrl != NULL);
	m_CurrentBmp.Detach();
	m_CurrentBmp.LoadBitmap(m_pFramesArray[m_CurrentFrame - 1]);
	pTargetCtrl->SetBitmap(m_CurrentBmp);
	m_CurrentFrame++;
	
	CDialog::OnTimer(nIDEvent);
}



Comments

  • quite fascinating...

    Posted by Legacy on 03/19/2002 12:00am

    Originally posted by: Narasimham

    It was quite fascinating...Thank you.
    

    Reply
  • Want to get some demo

    Posted by Legacy on 06/06/2001 12:00am

    Originally posted by: Karsten Noa

    HEllo can i get a demo project please.

    You can mail it to karstenn@asb-systemhaus.de

    Thanx

    Reply
  • how to add menu bar to the dialog

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

    Originally posted by: P.R. NARAYAN KUMAR

    this code guru is greate
    
    it has helped me in many ways
    i want to know from you that how will you add menu bar on the dialog box

    thank you
    narayan kumar.

    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
  • Bug

    Posted by Legacy on 04/29/1999 12:00am

    Originally posted by: SAEED R

    Detach does not always clear up the object from the bitmaps for some reason....after some iteration graphic disappears due to resource limitation...use deleteobjects() ..that takes care of it........

    Reply
  • Is it possible to get a demo of this ?

    Posted by Legacy on 04/13/1999 12:00am

    Originally posted by: Gregory Franz

    Is it possible to get a demo of this ? A zipped set of files and demo source code would be helpful. Thanks.
    

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

Top White Papers and Webcasts

  • Hybrid cloud platforms need to think in terms of sweet spots when it comes to application platform interface (API) integration. Cloud Velocity has taken a unique approach to tight integration with the API sweet spot; enough to support the agility of physical and virtual apps, including multi-tier environments and databases, while reducing capital and operating costs. Read this case study to learn how a global-level Fortune 1000 company was able to deploy an entire 6+ TB Oracle eCommerce stack in Amazon Web …

  • Savvy enterprises are discovering that the cloud holds the power to transform IT processes and support business objectives. IT departments can use the cloud to redefine the continuum of development and operations—a process that is becoming known as DevOps. Download the Executive Brief DevOps: Why IT Operations Managers Should Care About the Cloud—prepared by Frost & Sullivan and sponsored by IBM—to learn how IBM SmartCloud Application services provide a robust platform that streamlines …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds