播放WAV资源 |
| 作者:佚名 来源:不详 更新:2006-8-25 21:05:35 错误报告 我要投稿 |
首先,你必须手工将WAV文件加入到资源文件.rc 中。象这样:
<nameofsound> wave <location of wave.> 例子:
cool wave c:\projects\sounds\cool.wav 然后,在你需要播放WAV的地方加入下面的函数:
bool playresource(lpstr lpname) { bool brtn; lpstr lpres; handle hres; hrsrc hresinfo; hinstance nl=afxgetinstancehandle();
/* find the wave resource. */ hresinfo= findresource(nl,lpname,"wave"); if(hresinfo == null) return false; /* load the wave resource. */
hres = loadresource(nl,hresinfo); if (hres == null) return false;
/* lock the wave resource and play it. */ lpres=(lpstr)lockresource(hres); if(lpres==null) return false;
brtn = sndplaysound(lpres, snd_memory | snd_sync); if(brtn == null) return false;
/* free the wave resource and return success or failure. */ freeresource(hres); return true; }
最后,你就可以使用了。
playresource("cool");
|
|
| 文章录入:skyuu 责任编辑:skyuu |
|
| 【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |