www.pudn.com > AVIrep.rar > XAviPlay.cpp


// XAviPlay.cpp : Implementation of CXAviPlay 
#include "stdafx.h" 
#include "XAviPlay.h" 
#include "commctrl.h" 
 
///////////////////////////////////////////////////////////////////////////// 
// CXAviPlay 
 
CXAviPlay::CXAviPlay(HINSTANCE hInstance, long ResID, long Repeat,  
					 long Width, long Height, long lRows, BOOL Progress,  
					 long HalfLife, HWND hWndParent) 
{ 
	m_hInstance = hInstance;// Instance of calling process 
	m_ResID = ResID;		// ID of AVI-Resource 
	m_Repeat = Repeat;		// Number repetitions. -1 ... infinite 
	m_Width = Width;		// if you want to change the size of the Animation- 
	m_Height = Height;		// window you must specify both values. the AVI will be centered. 
	m_nRows = lRows;		// number of TextRows for additional text. 
	m_Progress = Progress;	// display the progressbar? 
	m_halfLife = HalfLife;	// halflife for progressbar. 
	m_hwndParent = hWndParent;	// parent window for centering the dialog box. 
	m_hwndAnim = NULL;		// hWnd: Animationwindow 
	m_hwndProgress = NULL;	// hWnd: progressbar 
	m_sText[0] = '\0';		// additional text. 
	m_StartTime = 0L;		// starting time for progressbar. 
} 
 
CXAviPlay::~CXAviPlay() 
{ 
} 
 
LRESULT CXAviPlay::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 
{ 
	long lStyle = WS_CHILD|ACS_TRANSPARENT; 
	// if both, height and width is specified, we center the AVI regarding to new window size. 
	lStyle = (m_Width>0&&m_Height>0) ? lStyle|=ACS_CENTER : lStyle; 
 
	m_hwndAnim = Animate_Create(m_hWnd, IDD_XAVIPLAY, lStyle, m_hInstance); 
	if (!m_hwndAnim)	return 1;	// creation failed. 
 
	RECT rect; 
	if (Animate_Open(m_hwndAnim, MAKEINTRESOURCE(m_ResID))) 
	{ 
		if (lStyle&ACS_CENTER) 
		{ 
			// we have to calculate the window-size. because default is 0/0 when ACS_CENTER 
			::MoveWindow(m_hwndAnim, 0, 0, m_Width, m_Height, FALSE); 
			::SetWindowPos(m_hwndAnim, HWND_BOTTOM, 0, 0, m_Width, m_Height, SWP_NOMOVE|SWP_NOSIZE); 
		} 
		::GetClientRect(m_hwndAnim, &rect);	// for calculating bounding rectangle. 
		::ShowWindow(m_hwndAnim, SW_SHOW); 
	} 
	else  
	{ 
		::DestroyWindow(m_hwndAnim); 
		m_hwndAnim = NULL; 
		return 1; 
	} 
 
	Animate_Play(m_hwndAnim, 0, -1, m_Repeat);	// we play all the frames, starting with the first one. 
	RECT fullrect, clienrect; 
	::GetWindowRect(m_hWnd, &fullrect); 
	::GetClientRect(m_hWnd, &clienrect); 
	long bx = fullrect.right - fullrect.left + clienrect.left - clienrect.right; 
	long by = fullrect.bottom - fullrect.top - clienrect.bottom + clienrect.top; 
 
	long lHeight = (long)(by+rect.bottom-rect.top);	// flat height. 
	// calculating height, if we display additional text, resp. a progress bar. 
	lHeight+=(m_nRows>0) ? (long)((m_nRows+2)*CONTROLHEIGHT) : 0; 
	lHeight+=(m_Progress>0) ? (long)(1.5*CONTROLHEIGHT) : 0; 
	long lWidth = rect.right-rect.left+bx; 
	::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, lWidth, lHeight, SWP_NOMOVE|SWP_NOREPOSITION); 
	CenterWindow(m_hwndParent); 
	// looking for the static control. 
	HWND hwndControl = ::GetDlgItem(m_hWnd, IDC_TEXT); 
	if (!hwndControl)	return 1; 
	if (m_nRows) 
	{ 
		::GetClientRect(m_hWnd, &clienrect); 
		// calculating the size of the static. 
		::SetWindowPos(hwndControl, HWND_BOTTOM, MARGIN,  
			(long)(clienrect.bottom-((m_nRows+1+m_Progress)*CONTROLHEIGHT)),  
			clienrect.right-clienrect.left-(2*MARGIN), (long)(m_nRows*CONTROLHEIGHT), SWP_NOREPOSITION); 
	} 
	else	::ShowWindow(hwndControl, SW_HIDE);	// no text: we don't show the static. 
	// processing the progressbar. 
	m_hwndProgress = ::GetDlgItem(m_hWnd, IDC_PROGRESSBAR); 
	if (!m_Progress)	::ShowWindow(m_hwndProgress, SW_HIDE);	// no progressbar to show. 
	else  
	{ 
		::GetClientRect(m_hWnd, &clienrect); 
		// calculating size of progressbar. 
		::SetWindowPos(m_hwndProgress, HWND_BOTTOM, MARGIN,  
			(long)(clienrect.bottom-(1.5*CONTROLHEIGHT)),  
			clienrect.right-clienrect.left-(2*MARGIN), (long)(CONTROLHEIGHT), SWP_NOREPOSITION); 
		::SendMessage(m_hwndProgress, PBM_SETRANGE, (WPARAM)0, MAKELPARAM(0, lMaxRange)); 
		m_StartTime = timeGetTime();	// important for setting progressbar-values. 
	} 
	return 1;  // Let the system set the focus 
} 
 
LRESULT CXAviPlay::OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) 
{ 
	EndDialog(wID); 
	return 0; 
} 
 
LRESULT CXAviPlay::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) 
{ 
	EndDialog(wID); 
	return 0; 
} 
 
void CXAviPlay::ResetProgressBar() 
{ 
	m_StartTime = timeGetTime();	// resetting the starting time leads to new drawing. 
}