#include <MMSystem.h>
MCI_OPEN_PARMS op;
BOOL flag;
void CcdDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
if (flag==FALSE)
{
flag=TRUE;
op.dwCallback=NULL;
op.lpstrAlias=NULL;
op.lpstrElementName=_T("D:\\见习爱神.mp3");
op.wDeviceID=NULL;
UINT rs;
rs=mciSendCommand(NULL,MCI_OPEN,MCI_OPEN_ELEMENT,(DWORD)&op);
if (rs==0)
{
MCI_PLAY_PARMS pp;
pp.dwCallback=NULL;
mciSendCommand(op.wDeviceID,MCI_PLAY,MCI_NOTIFY,(DWORD)&pp);
}
}
}
void CcdDlg::OnBnClickedButton2()
{
// TODO: 在此添加控件通知处理程序代码
MCI_GENERIC_PARMS gp;
gp.dwCallback=NULL;
mciSendCommand(op.wDeviceID,MCI_CLOSE,MCI_WAIT,(DWORD)&gp);
flag=FALSE;
}
连接附加库文件需要添加winmm.lib