//set the WAV file name to be played
mciOpenParms.lpstrElementName=pFileName;
//first open the device
DWORD dwResult=mciSendCommand(m_nDeviceID,MCI_OPEN,
MCI_OPEN_ELEMENT,(DWORD)(LPVOID)&mciOpenParms);
//display error message if failed
if(dwResult)
DisplayErrorMsg(dwResult);
//if successful,instruct the device to play the WAV file
else
{
//save element indentifier
m_nElementID=mciOpenParms.wDeviceID;
MCI_PLAY_PARMS mciPlayParms;
//set the window that will receive notification message
mciPlayParms.dwCallback=(DWORD)pWnd->m_hWnd;
//instruct device to play file
dwResult=mciSendCommand(m_nElementID,MCI_PLAY,
MCI_NOTIFY,(DWORD)(LPVOID)&mciPlayParms);
//display error and close element if failed
if(dwResult)
{
DisplayErrorMsg(dwResult);
Stop();
}
}
//return result of MCI operation
return dwResult;
}
DWORD CWave::Stop()
{
DWORD dwResult=0;
//close if element is currently open
if(m_nElementID)
{
dwResult=mciSendCommand(m_nElementID,MCI_CLOSE,NULL,NULL);
//display error message if failed
if(dwResult)
DisplayErrorMsg(dwResult);
//set identifier to closed state
else
m_nElementID=0;
}
return dwResult;
}
void CWave::DisplayErrorMsg(DWORD dwError)
{
//check if there was an error
if(dwError)
{
//character string that contains error message
char szErrorMsg[MAXERRORLENGTH];