Currently viewing: GipsySoft » Front Page» QHTM

class CQHTMImageABC

CQHTMImageABC

This class is used by users of QHTM to hand images to QHTM. QHTM uses an image callback function to retrieve a CQHTMImageABC based object, QHTM handles destroying the object by a single call to Destroy.

Functions

virtual BOOL DrawFrame( UINT nFrame, HDC hdc, int left, int top ) const = 0;

Draw a single frame. If you only have one frame then nFrame will be zero.

virtual BOOL StretchFrame( UINT nFrame, HDC hdc, int left, int top, int right, int bottom ) const = 0;

Stratch-draw a single frame. If you only have one frame then nFrame will be zero.

virtual UINT GetFrameCount() const = 0;

Return the number of frames your image has.

virtual const SIZE &GetSize() const = 0;

Return the size in pixels of the image.

virtual UINT GetFrameTime( UINT nFrame ) const = 0;

Return the display time in milliseconds for the given frame

virtual void Destroy() = 0;

Destroy the image and free any resources associated with it.

virtual UINT GetAnimationLoopCount() const = 0;

Return the number of times this animation might loop. 0 to animate forever.

Example

Here is an example of an object that can function as an image when used in QHTM. It's a contrived example but it works really well.


//	Header...
class CTimeImage : public CQHTMImageABC
{
public:
	CTimeImage();
	virtual ~CTimeImage();

	virtual BOOL DrawFrame( UINT f, HDC hdc, int l, int t ) const;
	virtual BOOL StretchFrame( UINT f, HDC hdc, int l, int t, int r, int b ) const;

	//
	//	Return the number of frames in this image
	virtual UINT GetFrameCount() const { return 2; }

	//
	//	Return the the size, in pixels, of this image
	virtual const SIZE &GetSize() const { return m_size; }

	//
	//	Return the time, in milliseconds, a frame remains on screen
	virtual int GetFrameTime( UINT  ) const { return 1000; }

	//
	//	Destroy this image
	virtual void Destroy() { delete this; }

	virtual UINT GetAnimationLoopCount() const
	{
		return 0;
	}

private:
	SIZE m_size;
};

//	Implementation...
const int knBorder = 4;

CTimeImage::CTimeImage()
{

	HDC hdc = ::GetDC( NULL );
	HGDIOBJ hOld = SelectObject( hdc, GetStockObject( DEFAULT_GUI_FONT ) );
	TCHAR szBuffer[ 64 ];
	time_t time = ::time( NULL );
	tm *tmNow = localtime( &time );
	int nLength = strftime( szBuffer, 64, _T("%H:%M:%S"), tmNow );
	GetTextExtentPoint32( hdc, szBuffer, nLength, &m_size );
	SelectObject( hdc, hOld );

	::ReleaseDC( NULL, hdc );

	m_size.cx += knBorder * 2;
	m_size.cy += knBorder * 2;

}

CTimeImage::~CTimeImage()
{

}


BOOL CTimeImage::DrawFrame( UINT , HDC hdc, int left, int top ) const
{
	RECT rc = { left, top, left + m_size.cx, top + m_size.cy };

	DrawFrameControl( hdc, &rc, DFC_BUTTON, DFCS_BUTTONPUSH );
	left += knBorder;
	top += knBorder;

	TCHAR szBuffer[ 64 ];
	time_t time = ::time( NULL );
	tm *tmNow = localtime( &time );
	int nLength = strftime( szBuffer, 64, _T("%H:%M:%S"), tmNow );

	HGDIOBJ hOld = SelectObject( hdc, GetStockObject( DEFAULT_GUI_FONT ) );
	SetBkMode( hdc, TRANSPARENT );
	TextOut( hdc, left, top, szBuffer, nLength );
	SelectObject( hdc, hOld );

	return TRUE;
}


//
//	Note that this mostly works just great. However, when printing
//	it will display very-very small indeed.
//	It would be better if we properly scaled our output to the
//	values QHTM tells us.
BOOL CTimeImage::StretchFrame( UINT, HDC hdc, int left, int top, int , int ) const
{
	return DrawFrame( 0, hdc, left, top ) ;
}

See also funcQHTMImageCallback QHTM_OPT_SET_IMAGE_CALLBACK