www.pudn.com > qiyehetongguanli.rar > RxMCI.cpp


// RxMCI.cpp: implementation of the RxMCI class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "htglxt.h" 
#include "RxMCI.h" 
#include "mmsystem.h" 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
RxMCI::RxMCI() 
{ 
	m_IsOpen=false; 
	m_IsPlay=true; 
} 
 
RxMCI::~RxMCI() 
{ 
	if(m_nElementID) 
		mciSendCommand(m_nElementID,MCI_CLOSE,NULL,NULL); 
	if(m_nDeviceID) 
		mciSendCommand(m_nDeviceID,MCI_CLOSE,NULL,NULL); 
} 
 
void RxMCI::Open(char* lpstrDeviceType) 
{ 
	if(m_IsOpen==true) 
		return; 
	m_IsOpen==true; 
	MCI_OPEN_PARMS mciOpenParms; 
	mciOpenParms.lpstrDeviceType=lpstrDeviceType; 
	m_lpDeviceType=lpstrDeviceType; 
	DWORD dParms; 
	dParms=mciSendCommand(NULL,MCI_OPEN,MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID|MCI_WAIT,(DWORD)(LPVOID)&mciOpenParms); 
	if(dParms) 
		DisplayErrorMsg(dParms); 
	m_nDeviceID=mciOpenParms.wDeviceID; 
} 
 
void RxMCI::DisplayErrorMsg(DWORD dParam) 
{ 
	char cMsg[MAXERRORLENGTH]; 
	if(!mciGetErrorString(dParam,cMsg,sizeof(cMsg))) 
		strcpy(cMsg,"未知错误!"); 
	//::MessageBox(NULL,cMsg,"系统提示",MB_OK|MB_ICONSTOP); 
} 
 
void RxMCI::Play(char* lpFileName,CWnd* pWnd) 
{ 
	DWORD dParms; 
	MCI_OPEN_PARMS mciOpenParms; 
	memset(&mciOpenParms,0,sizeof(MCI_OPEN_PARMS)); 
	mciOpenParms.lpstrElementName=lpFileName; 
	dParms=mciSendCommand(m_nDeviceID,MCI_OPEN,MCI_OPEN_ELEMENT,(DWORD)(LPVOID)&mciOpenParms); 
	if(dParms) 
	{ 
		DisplayErrorMsg(dParms); 
		return; 
	} 
	m_nElementID=mciOpenParms.wDeviceID; 
	MCI_PLAY_PARMS mciPlayParms; 
	mciPlayParms.dwCallback=(DWORD)pWnd->GetSafeHwnd(); 
	if(m_lpDeviceType==(LPSTR)MCI_DEVTYPE_SEQUENCER) 
		dParms=mciSendCommand(m_nElementID,MCI_PLAY,MCI_NOTIFY,(DWORD)(LPVOID)&mciPlayParms); 
	else 
		dParms=mciSendCommand(m_nDeviceID,MCI_PLAY,MCI_NOTIFY,(DWORD)(LPVOID)&mciPlayParms); 
	if(dParms) 
		DisplayErrorMsg(dParms); 
	m_IsPlay=true; 
} 
void RxMCI::Close() 
{ 
	DWORD dParms; 
	if(m_nDeviceID) 
		dParms=mciSendCommand(m_nDeviceID,MCI_CLOSE,NULL,NULL); 
	if(dParms) 
		DisplayErrorMsg(dParms); 
} 
 
void RxMCI::Stop() 
{ 
	DWORD dParms; 
	if(m_nElementID) 
		dParms=mciSendCommand(m_nElementID,MCI_CLOSE,NULL,NULL); 
	if(dParms) 
		DisplayErrorMsg(dParms); 
} 
 
 
bool RxMCI::IsPlay() 
{ 
	return m_IsPlay; 
}