www.pudn.com > 毕业留念册.rar > Music.cpp
// Music.cpp: implementation of the CMusic class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Browse.h"
#include "Music.h"
#include "mmsystem.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#define WM_MYMESSAGE WM_USER+6
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMusic::CMusic()
{
m_flag=TRUE;
m_Index=0;
}
CMusic::~CMusic()
{
}
void CMusic::PlayMusic()
{
//m_MusicPath=m_PathList[m_PathList.GetSize()-1];
MCI_OPEN_PARMS mciopenparms;
MCI_PLAY_PARMS mciplayparms;
mciopenparms.lpstrElementName=m_MusicPath;
mciopenparms.lpstrDeviceType=NULL;
mciSendCommand(0,MCI_OPEN,MCI_DEVTYPE_WAVEFORM_AUDIO,(DWORD)(LPVOID)&mciopenparms);
m_count=mciopenparms.wDeviceID;
//mciplayparms.dwCallback=(DWORD)GetSafeHwnd();
m_CdLen=GetInfo(MCI_STATUS_LENGTH);
if(m_flag==TRUE)
m_CdFrom=MCI_MAKE_HMS(0,0,0);
m_CdTo=MCI_MAKE_HMS(MCI_HMS_HOUR(m_CdLen),MCI_HMS_MINUTE(m_CdLen),MCI_HMS_SECOND(m_CdLen));
mciplayparms.dwFrom=m_CdFrom;
mciplayparms.dwTo=m_CdTo;
mciSendCommand(m_count,MCI_PLAY,MCI_TO|MCI_FROM,(DWORD)(LPVOID)& mciplayparms);
}
DWORD CMusic::GetInfo(DWORD item)
{
MCI_STATUS_PARMS mcistatusparms;
// mcistatusparms.dwCallback=(DWORD)GetSafeHwnd();
mcistatusparms.dwItem=item;
mcistatusparms.dwReturn=0;
mciSendCommand(m_count,MCI_STATUS,MCI_STATUS_ITEM,(DWORD)&mcistatusparms);
return mcistatusparms.dwReturn;
}
void CMusic::StopMusic()
{
m_CdFrom=MCI_MAKE_HMS(0,0,0);
mciSendCommand(m_count,MCI_CLOSE,0,NULL);
m_count=0;
}
void CMusic::SetMusicPath(CString path)
{
m_MusicPath=path;
}
void CMusic::PauseMusic()
{
m_flag=FALSE;
DWORD dwsf=GetInfo(MCI_STATUS_POSITION);
m_CdFrom=MCI_MAKE_MSF(MCI_MSF_MINUTE(dwsf),MCI_MSF_SECOND(dwsf),
MCI_MSF_FRAME(dwsf));
mciSendCommand(m_count,MCI_CLOSE,0,NULL);
m_count=0;
}
void CMusic::PlayFronMusic(HWND hWnd)
{
/* if(!(m_PathList.GetSize()==0))
{
if(this->GetCurentMusic(m_MusicPath)==(m_PathList.GetSize()-1))
{
MessageBox(hWnd,"已经到第一首了……","提示",MB_ICONINFORMATION);
StopMusic();
}
else
{
int n=this->GetCurentMusic(m_MusicPath)+1;
StopMusic();
m_MusicPath=m_PathList[n];
//m_Music.m_MusicPath=m_BgMusic;
PlayMusic();
}
}
else
MessageBox(hWnd,"请先加入背景音乐……","提示",MB_ICONINFORMATION);
*/
if(m_PathList.GetSize()!=0)
{
StopMusic();
if(--m_Index<=0)
m_Index+=m_PathList.GetSize();
m_MusicPath=m_PathList[m_Index];
PlayMusic();
}
}
void CMusic::PlayNextMusic(HWND hWnd)
{
if(m_PathList.GetSize()!=0)
{
int max=m_PathList.GetSize();
if(++m_Index>=max)
{
m_Index=m_Index%max;
}
StopMusic();
m_MusicPath=m_PathList[m_Index];
PlayMusic();
}
}
int CMusic::GetCurentMusic(CString str)
{
int curent=0;
for(int i=0;i