void CMediaPlayerDlg::OnClose() { m_ActiveMovie.CloseWindow();//關閉窗口 } void CMediaPlayerDlg::OnOpen() { char szFileFilter[]="Mp3 File(*.mp3)|*.mp3|" "Wma File(*.wma)|*.wma|" "Video File(*.dat)|*.dat|" "Wave File(*.wav)|*.wav|" "AVI File(*.avi)|*.avi|" "Movie File(*.mov)|*.mov|" "Media File(*.mmm)|*.mmm|" "Mid File(*.mid;*,rmi)|*.mid;*.rmi|" "MPEG File(*.mpeg)|*.mpeg|" "All File(*.*)|*.*||";//文件類型過濾 CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFileFilter); if(dlg.DoModal()==IDOK){ CString PathName=dlg.GetPathName(); PathName.MakeUpper(); m_ActiveMovie.SetFileName(PathName); } } void CMediaPlayerDlg::OnPlay() { m_ActiveMovie.Run();//播放文件 SetTimer(0,20,NULL);//設置定時器 } void CMediaPlayerDlg::OnStop() { m_ActiveMovie.Stop();//中止播放文件 KillTimer(0);//關掉定時器 } void CMediaPlayerDlg::OnPause() { m_ActiveMovie.Pause(); } void CMediaPlayerDlg::OnUpper() { long Volume=m_ActiveMovie.GetVolume(); m_ActiveMovie.Pause(); m_ActiveMovie.SetVolume(Volume+100); m_ActiveMovie.Run(); } void CMediaPlayerDlg::OnLower() { long Volume=m_ActiveMovie.GetVolume(); m_ActiveMovie.Pause(); m_ActiveMovie.SetVolume(Volume-100); m_ActiveMovie.Run(); } void CMediaPlayerDlg::OnRepeat() { if(!isRepeat){ isRepeat=TRUE; SetDlgItemText(IDC_STATIC2,"Status:Repeat"); } else{ isRepeat=FALSE; SetDlgItemText(IDC_STATIC2,"Status:Normal"); } } void CMediaPlayerDlg::OnFulscreeen() { m_ActiveMovie.Pause(); m_ActiveMovie.SetFullScreenMode(true); m_ActiveMovie.SetMovieWindowSize(SW_SHOWMAXIMIZED); m_ActiveMovie.Run(); } (註釋:函數OnTimer()需經過ClassWizard(Ctrl+W)來添加,不能直接複製) void CMediaPlayerDlg::OnTimer(UINT nIDEvent) { double CurrentPos=m_ActiveMovie.GetCurrentPosition(); if(CurrentPos==0&&isRepeat)//若是當前是文件的起始位置並且爲重複播放狀態 m_ActiveMovie.Run(); CDialog::OnTimer(nIDEvent); } |
BOOL CMediaPlayerDlg::OnInitDialog() { CDialog::OnInitDialog(); isRepeat=FALSE; …… } |
CRoundButton m_FullScreen; CRoundButton m_Repeat; CRoundButton m_Upper; CRoundButton m_Lower; CRoundButton m_Close; CRoundButton m_Exit; CRoundButton m_Stop; CRoundButton m_Play; CRoundButton m_Pause; CRoundButton m_Open; |