网站导航免费论文 原创论文 论文搜索 原创论文 网学软件 学术大家 资料中心 会员中心 问题解答 原创论文 论文素材 设计下载 最新论文 下载排行 论文上传 在线投稿 联系我们
返回网学首页
网学联系
最新论文 推荐专题 热门论文 素材专题
当前位置: 网学 > 编程文档 > VC++ > 正文
大型WAV文件的播放
来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/15
下载{$ArticleTitle}原创论文样式


public: DWORD OpenDevice();

DWORD CloseDevice();

DWORD Play(CWnd *pParentWnd,LPCSTR pFileName);

DWORD Stop(); //Implementation protected:

void DisplayErrorMsg(DWORD dwError); //Members protected: MCIDEVICEID m_nDeviceID;

MCIDEVICEID m_nElementID;   

};   

//Cwave类的实现代码,Cwave.cpp  

#include   

#include "cwave.h"   

CWave::CWave(){   

m_nDeviceID=0;   

m_nElementID=0;   

}   

CWave::~CWave()   

{   

if(m_nElementID)   

Stop();   

if(m_nDeviceID)    CloseDevice();   

}   

DWORD CWave::OpenDevice()   

{   

DWORD dwResult=0;   

if (m_nDeviceID) MCI_OPEN_PARMS mciOpenParms;

mciOpenParms.lpstrDeviceType=(LPSTR)MCI_DEVTYPE_WAVEFORM_AUDIO; //open the wave device   

dwResult=mciSendCommand(NULL,MCI_OPEN, MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID|MCI_WAIT, (DWORD)(LPVOID)&mciOpenParms); //save device identifier,will use eith other MCI commands

m_nDeviceID=mciOpenParms.wDeviceID; //display error message if failed if(dwResult)

DisplayErrorMsg(dwResult);

} //return result of MCI operation return dwResult;   }   

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(); }

} //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];  
  • 下一篇资讯: 详析VC中坐标系的建立
  • 网学推荐

    免费论文

    原创论文

    浏览:
    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
    湘ICP备09003080号