void CMIDIPlayDlg::OnOpen()
{
// TODO: Add your control notification handler code here
CFileDialog file(TRUE,"","",OFN_FILEMUSTEXIST,"(*.mid及*.wav文件)||*.wav||*.mid");
if (file.DoModal()==IDOK)
{
strFileName=file.GetFileName();
strFileExt=file.GetFileExt();
}
this -> SetWindowText("请单击Play按钮,欣赏"+strFileName);
}
void CMIDIPlayDlg::OnPlay()
{
// TODO: Add your control notification handler code here
isPause=true;
SetTimer(1,33,NULL);
mciSendCommand(m_wDeviceID,MCI_CLOSE,0,NULL);
MCI_OPEN_PARMS mciOpen;
MCI_PLAY_PARMS mciPlay;
mciOpen.lpstrElementName=strFileName.GetBuffer(strFileName.GetLength());
mciSendCommand(NULL,MCI_OPEN,MCI_OPEN_ELEMENT,(DWORD)(LPVOID)&mciOpen);
m_wDeviceID=mciOpen.wDeviceID;
MCI_STATUS_PARMS mciStatusParms;
mciStatusParms.dwItem=MCI_STATUS_LENGTH;
mciSendCommand(m_wDeviceID,MCI_STATUS,MCI_WAIT|MCI_STATUS_ITEM,(DWORD)(LPVOID)&mciStatusParms);
m_dLength=mciStatusParms.dwReturn;
mciSendCommand(m_wDeviceID,MCI_PLAY,0,(DWORD)(LPVOID)&mciPlay);
m_position.SetRange(0,m_dLength);
m_position.SetPos(0);
}
void CMIDIPlayDlg::OnStop()
{
// TODO: Add your control notification handler code here
mciSendCommand(m_wDeviceID,MCI_STOP,0,NULL);
//m_position.SetPos(0);
}
void CMIDIPlayDlg::OnPause()
{
// TODO: Add your control notification handler code here
if(isPause)
{
isPause=FALSE;
MCI_GENERIC_PARMS mciPause;
mciSendCommand(m_wDeviceID,MCI_PAUSE,0,(DWORD)(LPVOID)&mciPause);
}
else
{
isPause=TRUE;
if(strFileExt=="mid"||strFileExt=="MID")
{
MCI_STATUS_PARMS mciStatusParms;
MCI_PLAY_PARMS mciPlayParms;
mciStatusParms.dwItem=MCI_STATUS_POSITION;
mciSendCommand(m_wDeviceID,MCI_STATUS,MCI_STATUS_ITEM,(DWORD)(LPVOID)&mciStatusParms);
}
else
{
MCI_GENERIC_PARMS mciResume;
mciSendCommand(m_wDeviceID,MCI_RESUME,0,(DWORD)(LPVOID)&mciResume);
}
}
}
void CMIDIPlayDlg::OnPrevious()
{
// TODO: Add your control notification handler code here
isPause=true;
MCI_STATUS_PARMS mciStatusParms;
MCI_PLAY_PARMS mciPlayParms;
mciStatusParms.dwItem=MCI_STATUS_POSITION;
mciSendCommand(m_wDeviceID,MCI_STATUS,MCI_STATUS_ITEM,(DWORD)(LPVOID)&mciStatusParms);
dCurrentPosition=mciStatusParms.dwReturn;
if(dCurrentPosition<=(m_dLength/16))
{
mciSendCommand(m_wDeviceID,MCI_SEEK,MCI_SEEK_TO_START,NULL);
mciSendCommand(m_wDeviceID,MCI_PLAY,0,(DWORD)(LPVOID)&mciPlayParms);
}
else
{
mciPlayParms.dwFrom=dCurrentPosition-(DWORD)(m_dLength/16);
mciSendCommand(m_wDeviceID,MCI_PLAY,MCI_FROM,(DWORD)(LPVOID)&mciPlayParms);
}
}
void CMIDIPlayDlg::OnNext()
{
// TODO: Add your control notification handler code here
isPause=true;
MCI_STATUS_PARMS mciStatusParms;
MCI_PLAY_PARMS mciPlayParms;
mciStatusParms.dwItem=MCI_STATUS_POSITION;
mciSendCommand(m_wDeviceID,MCI_STATUS,MCI_STATUS_ITEM,(DWORD)(LPVOID)&mciStatusParms);
dCurrentPosition=mciStatusParms.dwReturn;
if((m_dLength-dCurrentPosition)<=(m_dLength/16))
{
mciSendCommand(m_wDeviceID,MCI_SEEK,MCI_SEEK_TO_END,NULL);
mciSendCommand(m_wDeviceID,MCI_PLAY,0,(DWORD)(LPVOID)&mciPlayParms);
}
else
{
mciPlayParms.dwFrom=dCurrentPosition+(DWORD)(m_dLength/16);
mciSendCommand(m_wDeviceID,MCI_PLAY,MCI_FROM,(DWORD)(LPVOID)&mciPlayParms);
}
}--------------------next---------------------
阅读(440) | 评论(0) | 转发(0) |