利用 VC6 內建 ActiveX 元件 ActiveMovieControl Object(quartz.dll),快速建立支援 MP3/WMA/WAV/AVI/MPEG 等格式的播放器,具備播放/暫停/停止/音量/全螢幕/重複播放功能。


MediaPlayerCActiveMovie3 m_ActiveMovieBN_CLICKED 處理函式void OnOpen() {
char filter[] = "MP3|*.mp3|WMA|*.wma|AVI|*.avi|MPG|*.mpg|所有檔|*.*||";
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, filter);
if (dlg.DoModal() == IDOK) {
CString path = dlg.GetPathName(); path.MakeUpper();
m_ActiveMovie.SetFileName(path);
}
}
void OnPlay() { m_ActiveMovie.Run(); SetTimer(0,20,NULL); }
void OnPause() { m_ActiveMovie.Pause(); }
void OnStop() { m_ActiveMovie.Stop(); KillTimer(0); }
void OnUpper() { long v=m_ActiveMovie.GetVolume(); m_ActiveMovie.SetVolume(v+100); }
void OnLower() { long v=m_ActiveMovie.GetVolume(); m_ActiveMovie.SetVolume(v-100); }
void OnFull() { m_ActiveMovie.SetFullScreenMode(TRUE); m_ActiveMovie.SetMovieWindowSize(SW_SHOWMAXIMIZED); m_ActiveMovie.Run(); }
BOOL isRepeat = FALSE;
void OnRepeat() {
isRepeat = !isRepeat;
SetDlgItemText(IDC_STATIC2, isRepeat ? "Status:Repeat" : "Status:Normal");
}
void OnTimer(UINT nID) {
if (m_ActiveMovie.GetCurrentPosition() == 0 && isRepeat)
m_ActiveMovie.Run();
CDialog::OnTimer(nID);
}
CRoundButtonRoundButton.h/.cpp(繼承 CButton,Owner-draw 圓形繪製)CButton 改為 CRoundButton#include "RoundButton.h"王凱明,復旦大學,doose@etang.com