Как сделать цикличным проигрывание MIDI-файла
|
LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { if(message==MM_MCINOTIFY) if(wParam!=MCI_NOTIFY_ABORTED) { if(m_bIsPlaing) { if(SetMidi()) PlayMidi(); } }
return CFrameWnd::WindowProc(message, wParam, lParam); }
BOOL CMainFrame::SetMidi() { StopMidi(); MCI_OPEN_PARMS OpenParm; OpenParm.dwCallback = (DWORD)GetSafeHwnd(); OpenParm.lpstrDeviceType = NULL; OpenParm.lpstrElementName = filename; DWORD flags=MCI_OPEN_ELEMENT; MCIERROR err; err=mciSendCommand(0, MCI_OPEN, flags,(DWORD)&OpenParm); if(!err){ m_nMidideviceID=OpenParm.wDeviceID; return TRUE; } else return FALSE; }
BOOL CMainFrame::PlayMidi(void) { MCI_PLAY_PARMS PlayParm; PlayParm.dwCallback =(DWORD)GetSafeHwnd(); PlayParm.dwFrom=0; MCIERROR err;
err=mciSendCommand(m_nMidideviceID,MCI_PLAY,MCI_FROM|MCI_NOTIFY,(DWORD)&PlayParm); if(!err) { m_bIsPlaing=TRUE; return TRUE; } m_bIsPlaing=FALSE; return FALSE; }
BOOL CMainFrame::StopMidi(void) { m_bIsPlaing=FALSE; MCI_GENERIC_PARMS generic_params; generic_params.dwCallback=(DWORD)GetSafeHwnd(); mciSendCommand(m_nMidideviceID,MCI_CLOSE,MCI_WAIT,(DWORD)&generic_params); return TRUE; } |