www.pudn.com > RecDemo.rar > SingleDialog.cpp


// SingleDialog.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "RecDemo.h" 
#include "SingleDialog.h" 
 
#include "io.h" 
#include "..\\..\\..\\..\\inc\\tc08a32.h" 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// SingleDialog dialog 
 
 
SingleDialog::SingleDialog(CWnd* pParent /*=NULL*/) 
	: CDialog(SingleDialog::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(SingleDialog) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
} 
 
 
void SingleDialog::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(SingleDialog) 
	DDX_Control(pDX, IDC_EDIT1, m_TimeText); 
	DDX_Control(pDX, IDC_LIST2, m_FileList); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(SingleDialog, CDialog) 
	//{{AFX_MSG_MAP(SingleDialog) 
	ON_BN_CLICKED(IDC_BUTTON_PLAY, OnButtonPlay) 
	ON_BN_CLICKED(IDC_BUTTON_PAUSE, OnButtonPause) 
	ON_WM_DESTROY() 
	ON_WM_TIMER() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// SingleDialog message handlers 
static	char	NowFileName[80]; 
static	bool	PlayFlag = false; 
static	bool	PauseFlag = false; 
static	int		StartTimeCount; 
int		StartTime; 
 
extern long	lBytesPerSecond; 
 
long	CalculateBytes( long lStartMilSecond ) 
{ 
	long	l; 
 
	l = lBytesPerSecond * lStartMilSecond / 1000; 
	return l; 
} 
 
void SingleDialog::OnButtonPlay()  
{ 
	// TODO: Add your control notification handler code here 
	int	Index; 
 
	if ( PlayFlag == false ) 
	{	// start play 
		Index = m_FileList.GetCurSel(); 
		m_FileList.GetText ( Index, NowFileName ); 
		StartTime = 0; 
		StartPlayFile ( 0, NowFileName, CalculateBytes(StartTime) ); 
		StartTimeCount = GetTickCount (); 
 
		// 
		PlayFlag = true; 
		((CButton *)GetDlgItem (IDC_BUTTON_PLAY))->SetWindowText ( "Stop" ); 
		((CButton *)GetDlgItem (IDC_BUTTON_PAUSE))->EnableWindow ( true ); 
	} 
	else 
	{	// stop play 
		StopPlayFile ( 0 ); 
 
		// 
		PlayFlag = false; 
		((CButton *)GetDlgItem (IDC_BUTTON_PLAY))->SetWindowText ( "Start" ); 
		PauseFlag = false; 
		((CButton *)GetDlgItem (IDC_BUTTON_PAUSE))->SetWindowText ( "Pause" ); 
		((CButton *)GetDlgItem (IDC_BUTTON_PAUSE))->EnableWindow ( false ); 
	} 
} 
 
void SingleDialog::OnButtonPause()  
{ 
	// TODO: Add your control notification handler code here 
	char	TmpStr[30]; 
 
	if ( PauseFlag == false ) {		// pause 
		StopPlayFile ( 0 ); 
 
		// 
		PauseFlag = true; 
		((CButton *)GetDlgItem (IDC_BUTTON_PAUSE))->SetWindowText ( "Continue" ); 
 
	} 
	else {				// continue 
		m_TimeText.GetWindowText ( TmpStr, 20 ); 
		double f = atof ( TmpStr ); 
		f = f * 1000; 
		StartTime = (int) f; 
		StartPlayFile ( 0, NowFileName, CalculateBytes(StartTime) );  // play to channel 0 
		StartTimeCount = GetTickCount (); 
 
		// 
		PauseFlag = false; 
		((CButton *)GetDlgItem (IDC_BUTTON_PAUSE))->SetWindowText ( "Pause" ); 
	} 
} 
 
BOOL SingleDialog::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	// TODO: Add extra initialization here 
	_finddata_t fileinfo; 
	long	FindHandle, l; 
	static	int	count = 0; 
 
	l = FindHandle = _findfirst ( ".\\*.pcm", &fileinfo ); 
	while ( l != -1 ) 
	{ 
		m_FileList.AddString ( fileinfo.name ); 
		l = _findnext ( FindHandle, &fileinfo ); 
	} 
 
	m_FileList.SetCurSel ( 0 ); 
 
	SetTimer ( 1010, 100, NULL ); 
 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void SingleDialog::OnDestroy()  
{ 
	CDialog::OnDestroy(); 
	 
	// TODO: Add your message handler code here 
	CDialog::OnDestroy(); 
	 
	// TODO: Add your message handler code here 
	if ( PlayFlag && !PauseFlag ) { 
		StopPlayFile(0); 
	} 
} 
 
void SingleDialog::OnTimer(UINT nIDEvent)  
{ 
	// TODO: Add your message handler code here and/or call default 
	int		NowCount, diff; 
	char	TmpStr[80]; 
 
	if ( PlayFlag && !PauseFlag ) 
	{ 
		NowCount = GetTickCount (); 
		diff = StartTime + (NowCount - StartTimeCount); 
		sprintf ( TmpStr, "%d.%d",  diff/1000, diff%1000 ); 
		m_TimeText.SetWindowText ( TmpStr ); 
 
		if ( CheckPlayEnd (0) ) 
		{ 
			OnButtonPlay(); 
		} 
	} 
 
	CDialog::OnTimer(nIDEvent); 
}