VC:大型WAV文件的播放(3)
DWORD CWave::CloseDevice()
{
DWORD dwResult=0;
//close if currently open
if(m_nDeviceID)
{
//close the MCI device
dwResult=mciSendCommand(m_nDeviceID,MCI_CLOSE,NULL,NULL);
//display error message if failed
if(dwResult)
DisplayErrorMsg(dwResult);
//set identifier to close state
else
m_nDeviceID=0;
}
//return result of MCI operation
return dwResult;
}
DWORD CWave::Play(CWnd* pWnd,LPCSTR pFileName)
{
MCI_OPEN_PARMS mciOpenParms;
//initialize structure
memset(&mciOpenParms,0,sizeof(MCI_OPEN_PARMS));
//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();
}
}
- 上一篇:没有了
- 下一篇:Visual C++与Delphi/C++Builder之比较(二)

