




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
./第一步:打開vc6.0,建立如圖所示mfc工程文件選擇基于對話框的確定刪除所有空間,建立如圖所示對話框屬性如下:播放IDC_open;添加IDC_fileopen;暫停IDC_pause;刪除IDC_del;停止IDC_stop;退出IDC_exit;音樂名編輯框IDC_filename;音量控制滑塊IDC_SLIDER1;音量控制編輯框IDC_vol;建立類向導對應如下:在工程文件,右鍵,插入,bitmap位圖引入你想插入的背景圖,必須是bmp格式的進入你的dlg.cpp文件在onpaint函數下添加代碼voidCMp3Dlg::OnPaint<>{ if<IsIconic<>> { CPaintDCdc<this>;//devicecontextforpainting SendMessage<WM_ICONERASEBKGND,<WPARAM>dc.GetSafeHdc<>,0>; //Centericoninclientrectangle intcxIcon=GetSystemMetrics<SM_CXICON>; intcyIcon=GetSystemMetrics<SM_CYICON>; CRectrect; GetClientRect<&rect>; intx=<rect.Width<>-cxIcon+1>/2; inty=<rect.Height<>-cyIcon+1>/2; //Drawtheicon dc.DrawIcon<x,y,m_hIcon>; } else { //CDialog::OnPaint<>; CPaintDCdc<this>; CRectrect; GetClientRect<&rect>; CDCdcMem; dcMem.CreateCompatibleDC<&dc>; CBitmapbmpBackground; bmpBackground.LoadBitmap<IDB_BITMAP6>;/IDB_BITMAP6是你的位圖地址 BITMAPbitmap; bmpBackground.GetBitmap<&bitmap>; CBitmap*pbmpOld=dcMem.SelectObject<&bmpBackground>; dc.StretchBlt<0,0,rect.Width<>,rect.Height<>,&dcMem,0,0,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY>; }}編譯運行,你就會看到背景有圖片了。插入-類,找到geneticclass,類名mp3.cpp你會發現在頭文件中多了一個mp3.h文件在mp3.h文件中添加代碼如下//Mp3.h:interfacefortheMp3class.////////////////////////////////////////////////////////////////////////#if!defined<AFX_MP3_H__20D325E5_A96A_43FE_A485_92F57C68DD0D__INCLUDED_>#defineAFX_MP3_H__20D325E5_A96A_43FE_A485_92F57C68DD0D__INCLUDED_#if_MSC_VER>1000#pragmaonce#endif//_MSC_VER>1000#include"Mmsystem.h"classMp3{public: Mp3<>; virtual~Mp3<>;HWNDm_hWnd;//????μ±?°′°?úμ???±ú DWORDDeviceID;//???¨2¥·?ò?à?μ?éè±?IDMCI_OPEN_PARMSmciopenparms;//???¨′ò?aò?à????tμ?2?êyvoidLoad<HWNDhwnd,CStringStrfilepath>; DWORDgetinformation<DWORDitem>; voidPlay<>; voidPause<>; voidresum<>; voidStop<>;};#endif//!defined<AFX_MP3_H__20D325E5_A96A_43FE_A485_92F57C68DD0D__INCLUDED_>在mp3.cpp中添加如下代碼//Mp3.cpp:implementationoftheMp3class.////////////////////////////////////////////////////////////////////////#include"stdafx.h"#include"Mp32¥·??÷.h"#include"Mp3.h"#ifdef_DEBUG#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#definenewDEBUG_NEW#endif////////////////////////////////////////////////////////////////////////Construction/Destruction//////////////////////////////////////////////////////////////////////Mp3::Mp3<>{}Mp3::~Mp3<>{}voidMp3::Load<HWNDhwnd,CStringStrfilepath>{ m_hWnd=hwnd; mciSendCommand<DeviceID,MCI_CLOSE,0,0>;//?ó?????t?°?è??3yé?′?éè?? mciopenparms.lpstrElementName=Strfilepath;//??ò?à????t?·??′???éè±? DWORDdwReturn; if<dwReturn=mciSendCommand<NULL,MCI_OPEN,MCI_OPEN_ELEMENT|MCI_WAIT,<DWORD><LPVOID>&mciopenparms>> { //è?1?′ò?a꧰ü£???3?′íD??¢′??úbuffer2¢??ê?3?′í?ˉ?? charbuffer[256]; mciGetErrorString<dwReturn,buffer,256>; MessageBox<hwnd,buffer,"3?′í?ˉ??",MB_ICONHAND|MB_ICONERROR|MB_ICONSTOP>; } DeviceID=mciopenparms.wDeviceID;//?à??ì?éè±?ààDí±ào?}DWORDMp3::getinformation<DWORDitem>{ //MCI?ó?ú???óμ?×′ì? MCI_STATUS_PARMSmcistatusparms; //′y??è?μ????? mcistatusparms.dwItem=item; mcistatusparms.dwReturn=0; //???à??ì?éè±?·¢?í??á?£???è?μ±?°μ?×′ì?2?êy mciSendCommand<DeviceID,MCI_STATUS,MCI_STATUS_ITEM,<DWORD>&mcistatusparms>; returnmcistatusparms.dwReturn;}voidMp3::Play<>{ MCI_PLAY_PARMSmciplayparms; mciplayparms.dwCallback=<DWORD>m_hWnd; mciplayparms.dwFrom=0;//??′?′óí·2¥·? mciSendCommand<DeviceID,MCI_PLAY,MCI_FROM|MCI_NOTIFY,<DWORD><LPVOID>&mciplayparms>;}voidMp3::Pause<>{ mciSendCommand<DeviceID,MCI_PAUSE,0,0>;}voidMp3::resum<>{ mciSendCommand<DeviceID,MCI_RESUME,0,0>;}voidMp3::Stop<>{ mciSendCommand<DeviceID,MCI_STOP,0,0>; mciSendCommand<DeviceID,MCI_CLOSE,0,0>;}在dlg.cpp文件的public中添加一行代碼:inthour,minute,second;在CMp3Dlg::CMp3Dlg<CWnd*pParent/*=NULL*/>中添加如下CMp3Dlg::CMp3Dlg<CWnd*pParent/*=NULL*/> :CDialog<CMp3Dlg::IDD,pParent>{ //{{AFX_DATA_INIT<CMp3Dlg> m_int=0; //}}AFX_DATA_INIT //NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32 m_hIcon=AfxGetApp<>->LoadIcon<IDI_ICON1>; hour=0;minute=0;second=0;}dlg.cpp中頭文件如下:#include"stdafx.h"#include"Mp32¥·??÷.h"#include"Mp32¥·??÷Dlg.h"#include"Mmsystem.h"#include"Digitalv.h"#include"Mp3.h"http://ò?á?????ó?μ?#pragmacomment<lib,"Winmm.lib">#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#endif在對話框中雙擊添加添加onfileopen函數,代碼如下voidCMp3Dlg::Onfileopen<>{ charfilefiler[]="mp3文件<*.mp3>|*.mp3|" "wma文件<*.wma>|*.wma|" "wav文件<*.wav>|*.wav|"; CFileDialogdlg<true,NULL,NULL,OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT|OFN_ENABLESIZING,filefiler>;if<dlg.DoModal<>==IDOK>{ CStringstrfilepath=dlg.GetPathName<>; CStringstrfilename=dlg.GetFileName<>; SetDlgItemText<IDC_filename,strfilename>; CStringmtime; CClientDCdc<this>; hour=0;minute=0;second=0; dc.SetBkColor<RGB<124,252,0>>;//設置放置計數器區域的外觀 dc.SetTextColor<RGB<255,255,203>>;//設置數字顯示的顏色 mtime.Format<"%02d:%02d:%02d",hour,minute,second>;//顯示時間進度 dc.TextOut<280,128,mtime>; Mp3mp3; mp3.Load<this->m_hWnd,strfilepath>; GetDlgItem<IDC_open>->EnableWindow<TRUE>; GetDlgItem<IDC_pause>->EnableWindow<TRUE>; GetDlgItem<IDC_stop>->EnableWindow<TRUE>; GetDlgItem<IDC_del>->EnableWindow<TRUE>;m_list.InsertString<m_list.GetCount<>,strfilename>;//獲取文件名m_list.SetCurSel<m_list.GetCount<>-1>;}雙擊播放,進入代碼,添加如下voidCMp3Dlg::Onopen<>{ CStringstrfilename; intindex=m_list.GetCurSel<>; CStringmtime; CClientDCdc<this>; Mp3mp3; hour=0;minute=0;second=0; dc.SetBkColor<RGB<124,252,0>>;//設置放置計數器區域的外觀 dc.SetTextColor<RGB<255,255,203>>;//設置數字顯示的顏色 mtime.Format<"%02d:%02d:%02d",hour,minute,second>;//顯示時間進度 dc.TextOut<280,128,mtime>; if<index==-1> { MessageBox<"請添加音樂">; return; } m_list.GetText<index,strfilename>; SetDlgItemText<IDC_filename,strfilename>;mp3.Stop<>; mp3.Load<this->m_hWnd,strfilename>; mp3.Play<>;SetTimer<0,1000,NULL>;}同理,暫停,停止,刪除,退出代碼如下voidCMp3Dlg::Onpause<>{ //TODO:Addyourcontrolnotificationhandlercodehere CStringstrtemp; Mp3mp3; GetDlgItemText<IDC_pause,strtemp>;//獲取按鈕狀態 if<strtemp.Compare<"暫停">==0> { mp3.Pause<>; SetDlgItemText<IDC_pause,"繼續">; KillTimer<0>;//取消計數器的顯示 } if<strtemp.Compare<"繼續">==0> { mp3.resum<>; SetTimer<0,1000,NULL>; SetDlgItemText<IDC_pause,"暫停">; }}voidCMp3Dlg::Onstop<>{ //TODO:Addyourcontrolnotificationhandlercodehere Mp3mp3; mp3.Stop<>; SetDlgItemText<IDC_pause,"暫停">; KillTimer<0>;//取消計數器的顯示 CStringmtime; CClientDCdc<this>; hour=0;minute=0;second=0; dc.SetBkColor<RGB<124,252,0>>;//設置放置計數器區域的外觀 dc.SetTextColor<RGB<255,255,203>>;//設置數字顯示的顏色 mtime.Format<"%02d:%02d:%02d",hour,minute,second>;//顯示時間進度 dc.TextOut<280,128,mtime>; GetDlgItem<IDC_open>->EnableWindow<FALSE>; GetDlgItem<IDC_pause>->EnableWindow<FALSE>; GetDlgItem<IDC_stop>->EnableWindow<FALSE>; GetDlgItem<IDC_del>->EnableWindow<FALSE>;}voidCMp3Dlg::Ondel<>{ UpdateData<TRUE>; Mp3mp3; intindex=m_list.GetCurSel<>; mp3.Stop<>; SetDlgItemText<IDC_filename,"">; KillTimer<0>; hour=0;minute=0;second=0;//歌曲時間置0 if<index!=CB_ERR> { m_list.DeleteString<index>; }}voidCMp3Dlg::Onexit<>{ //TODO:Addyourcontrolnotificationhandlercodehere CDialog::OnCancel<>;}ctrl+w打開類向導,如圖,添加ontimer函數代碼如下:voidCMp3Dlg::OnTimer<UINTnIDEvent>{ //TODO:Addyourmessagehandlercodehereand/orcalldefault CStringmtime; Mp3mp3; second++; CClientDCdc<this>; dc.SetBkColor<RGB<124,252,0>>;//設置放置計數器區域的外觀 dc.SetTextColor<RGB<255,255,203>>;//設置數字顯示的顏色if<second==60>//設置鐘表的顯示 { minute++;second=0; } if<minute==60> { hour++;minute=0; } mtime.Format<"%02d:%02d:%02d",hour,minute,second>;//顯示時間進度 dc.TextOut<280,128,mtime>; DWORDcdf=mp3.getinformation<MCI_STATUS_POSITION>; DWORDcdfrom; cdfrom=MCI_MAKE_MSF<MCI_MSF_MINUTE<cdf>,MCI_MSF_SECOND<cdf>,MCI_MSF_FRAME<cdf>>;//獲取當前播放文件的信息 UpdateData<false>; CDialog::OnTimer<nIDEvent>;}ctrl+w打開類向導添加函數如下voidCMp3Dlg::OnDblclkList<>//在列表中選中,雙擊左鍵播放音樂{ CStringmtime; Mp3mp3; CClientDCdc<this>; hour=0;minute=0;second=0; dc.SetBkColor<RGB<124,252,0>>;//設置放置計數器區域的外觀 dc.SetTextColor<RGB<255,255,203>>;//設置數字顯示的顏色 mtime.Format<"%02d:%02d:%02d",hour,minute,second>;//顯示時間進度 dc.TextOut<280,128,mtime>; CStringstrfilename; intindex=m_list.GetCurSel<>; m_list.GetText<index,strfilename>; SetDlgItemText<IDC_filename,strfilename>; mp3.Stop<>; mp3.Load<this->m_hWnd,strfilename>; mp3.Play<>;SetTimer<0,1000,NULL>; }打開類向導,添加函數如下voidCMp3Dlg::OnCustomdrawSlider1<NMHDR*pNMHDR,LRESULT*pResult>{ //TODO:Addyourcontrolnotificationhandlercodehere UpdateData<true>; m_int=m_slider.GetPos<>/10; Setvolumn<m_slider.GetPos<>>; UpdateData<false>; *pResult=0;}打開類向導,添加函數如下voidCMp3Dlg::OnReleasedcaptureSlider1<NMHDR*pNMHDR,LRESULT*pResult>{ //TODO:Addyourcontrolnotificationhandlercodehere Setvolumn<m_slider.GetPos<>>; *pResult=0;}添加聲音設置函數如下DWORDCMp3Dlg::Setvolumn<DWORDvol>{ MCI_DGV_SETAUDIO_PARMSmcisetvolumn; mcisetvolumn.dwCallback=NULL; mcisetvolumn.dwItem=MCI_DGV_SETAUDIO_VOLUME; mcisetvolumn.dwValue=vol;MCI_OPEN_PARMSmciopenparms; DWORDDeviceID; DeviceID=mciopenparms.wDeviceID; mciSendCommand<DeviceID,MCI_SETAUDIO,MCI_DGV_SETAUDIO_VALUE|MCI_DGV_SETAUDIO_ITEM,<DWORD><LPVOID>&mcisetvolumn>; // returnmcisetvolumn.dwValue; return0;}到此已經基本完成了,我們可以試聽一下接下來我們可以到包成exe可執行文件,為了去掉那個不好看的圖標,我們可以進入res文件夾,把原來的圖標刪掉,不過,你要放入一個cio格式的圖片作為圖標,cio格式網上有很多轉換的,刪掉原圖標后,程序會自動生成一個你放進去的圖標。接下來演示打包:工程,設置,或者按alt+f7,如圖設置組建,批組建,如圖創建完成后,你就會發現在你的工程文件中多了一個release文件夾,打開找到exe,這個文件就是打包好的,隨便放到哪里都可以執行,至此,工作基本完成了,最后附上源代碼,僅供參考dlg.cpp文件//Mp3播放器Dlg.cpp:implementationfile//#include"stdafx.h"#include"Mp3播放器.h"#include"Mp3播放器Dlg.h"#include"Mmsystem.h"#include"Digitalv.h"#include"Mp3.h"http://音量控制用到#pragmacomment<lib,"Winmm.lib">#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#endif///////////////////////////////////////////////////////////////////////////////CAboutDlgdialogusedforAppAboutclassCAboutDlg:publicCDialog{public: CAboutDlg<>;//DialogData //{{AFX_DATA<CAboutDlg> enum{IDD=IDD_ABOUTBOX}; //}}AFX_DATA //ClassWizardgeneratedvirtualfunctionoverrides //{{AFX_VIRTUAL<CAboutDlg> protected: virtualvoidDoDataExchange<CDataExchange*pDX>;//DDX/DDVsupport //}}AFX_VIRTUAL//Implementationprotected: //{{AFX_MSG<CAboutDlg> //}}AFX_MSG DECLARE_MESSAGE_MAP<>};CAboutDlg::CAboutDlg<>:CDialog<CAboutDlg::IDD>{ //{{AFX_DATA_INIT<CAboutDlg> //}}AFX_DATA_INIT}voidCAboutDlg::DoDataExchange<CDataExchange*pDX>{ CDialog::DoDataExchange<pDX>; //{{AFX_DATA_MAP<CAboutDlg> //}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP<CAboutDlg,CDialog> //{{AFX_MSG_MAP<CAboutDlg> //Nomessagehandlers //}}AFX_MSG_MAPEND_MESSAGE_MAP<>///////////////////////////////////////////////////////////////////////////////CMp3DlgdialogCMp3Dlg::CMp3Dlg<CWnd*pParent/*=NULL*/> :CDialog<CMp3Dlg::IDD,pParent>{ //{{AFX_DATA_INIT<CMp3Dlg> m_int=0; //}}AFX_DATA_INIT //NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32 m_hIcon=AfxGetApp<>->LoadIcon<IDI_ICON1>; hour=0;minute=0;second=0;}voidCMp3Dlg::DoDataExchange<CDataExchange*pDX>{ CDialog::DoDataExchange<pDX>; //{{AFX_DATA_MAP<CMp3Dlg> DDX_Control<pDX,IDC_LIST,m_list>; DDX_Control<pDX,IDC_SLIDER1,m_slider>; DDX_Text<pDX,IDC_vol,m_int>; //}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP<CMp3Dlg,CDialog> //{{AFX_MSG_MAP<CMp3Dlg> ON_WM_SYSCOMMAND<> ON_WM_PAINT<> ON_WM_QUERYDRAGICON<> ON_BN_CLICKED<ID_exit,Onexit> ON_NOTIFY<NM_CUSTOMDRAW,IDC_SLIDER1,OnCustomdrawSlider1> ON_BN_CLICKED<IDC_fileopen,Onfileopen> ON_BN_CLICKED<IDC_open,Onopen> ON_BN_CLICKED<IDC_pause,Onpause> ON_BN_CLICKED<IDC_stop,Onstop> ON_NOTIFY<NM_RELEASEDCAPTURE,IDC_SLIDER1,OnReleasedcaptureSlider1> ON_WM_TIMER<> ON_BN_CLICKED<IDC_del,Ondel> ON_LBN_DBLCLK<IDC_LIST,OnDblclkList> //}}AFX_MSG_MAPEND_MESSAGE_MAP<>///////////////////////////////////////////////////////////////////////////////CMp3DlgmessagehandlersBOOLCMp3Dlg::OnInitDialog<>{ CDialog::OnInitDialog<>; //Add"About..."menuitemtosystemmenu. //IDM_ABOUTBOXmustbeinthesystemcommandrange. ASSERT<<IDM_ABOUTBOX&0xFFF0>==IDM_ABOUTBOX>; ASSERT<IDM_ABOUTBOX<0xF000>; CMenu*pSysMenu=GetSystemMenu<FALSE>; if<pSysMenu!=NULL> { CStringstrAboutMenu; strAboutMenu.LoadString<IDS_ABOUTBOX>; if<!strAboutMenu.IsEmpty<>> { pSysMenu->AppendMenu<MF_SEPARATOR>; pSysMenu->AppendMenu<MF_STRING,IDM_ABOUTBOX,strAboutMenu>; } } //Settheiconforthisdialog.Theframeworkdoesthisautomatically //whentheapplication'smainwindowisnotadialog SetIcon<m_hIcon,TRUE>; //Setbigicon SetIcon<m_hIcon,FALSE>;//Setsmallicon SetWindowText<"MP3播放器">; MoveWindow<250,150,580,500>;//顯示時間控制 m_slider.SetRange<0,1000>;//移動圍 m_slider.SetPos<500>;//滑塊指針的初始位置 GetDlgItem<IDC_open>->EnableWindow<FALSE>; GetDlgItem<IDC_pause>->EnableWindow<FALSE>; GetDlgItem<IDC_stop>->EnableWindow<FALSE>; GetDlgItem<IDC_del>->EnableWindow<FALSE>; //TODO:Addextrainitializationhere returnTRUE;//returnTRUEunlessyousetthefocustoacontrol}voidCMp3Dlg::OnSysCommand<UINTnID,LPARAMlParam>{ if<<nID&0xFFF0>==IDM_ABOUTBOX> { CAboutDlgdlgAbout; dlgAbout.DoModal<>; } else { CDialog::OnSysCommand<nID,lParam>; }}//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,//thisisautomaticallydoneforyoubytheframework.voidCMp3Dlg::OnPaint<>{ if<IsIconic<>> { CPaintDCdc<this>;//devicecontextforpainting SendMessage<WM_ICONERASEBKGND,<WPARAM>dc.GetSafeHdc<>,0>; //Centericoninclientrectangle intcxIcon=GetSystemMetrics<SM_CXICON>; intcyIcon=GetSystemMetrics<SM_CYICON>; CRectrect; GetClientRect<&rect>; intx=<rect.Width<>-cxIcon+1>/2; inty=<rect.Height<>-cyIcon+1>/2; //Drawtheicon dc.DrawIcon<x,y,m_hIcon>; } else { //CDialog::OnPaint<>; CPaintDCdc<this>; CRectrect; GetClientRect<&rect>; CDCdcMem; dcMem.CreateCompatibleDC<&dc>; CBitmapbmpBackground; bmpBackground.LoadBitmap<IDB_BITMAP6>; BITMAPbitmap; bmpBackground.GetBitmap<&bitmap>; CBitmap*pbmpOld=dcMem.SelectObject<&bmpBackground>; dc.StretchBlt<0,0,rect.Width<>,rect.Height<>,&dcMem,0,0,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY>; }}//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags//theminimizedwindow.HCURSORCMp3Dlg::OnQueryDragIcon<>{ return<HCURSOR>m_hIcon;}voidCMp3Dlg::Onexit<>{ //TODO:Addyourcontrolnotificationhandlercodehere CDialog::OnCancel<>;}voidCMp3Dlg::OnCustomdrawSlider1<NMHDR*pNMHDR,LRESULT*pResult>{ //TODO:Addyourcontrolnotificationhandlercodehere UpdateData<true>; m_int=m_slider.GetPos<>/10; Setvolumn<m_slider.GetPos<>>; UpdateData<false>; *pResult=0;}voidCMp3Dlg::Onfileopen<>{ charfilefiler[]="mp3文件<*.mp3>|*.mp3|" "wma文件<*.wma>|*.wma|" "wav文件<*.wav>|*.wav|"; CFileDialogdlg<true,NULL,NULL,OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT|OFN_ENABLESIZING,filefiler>;if<dlg.DoModal<>==IDOK>{ CStringstrfilepath=dlg.GetPathName<>; CStringstrfilename=dlg.GetFileName<>; SetDlgItemText<IDC_filename,strfilename>; CStringmtime; CClientDCdc<this>; hour=0;minute=0;second=0; dc.SetBkColor<RGB<124,252,0>>;//設置放置計數器區域的外觀 dc.SetTextColor<RGB<255,255,203>>;//設置數字顯示的顏色 mtime.Format<"%02d:%02d:%02d",hour,minute,second>;//顯示時間進度 dc.TextOut<280,128,mtime>; Mp3mp3; mp3.Load<this->m_hWnd,strfilepath>; GetDlgItem<IDC_open>->EnableWindow<TRUE>; GetDlgItem<IDC_pause>->EnableWindow<TRUE>; GetDlgItem<IDC_stop>->EnableWindow<TRUE>; GetDlgItem<IDC_del>->EnableWindow<TRUE>;m_list.InsertString<m_list.GetCount<>,strfilename>;//獲取文件名m_list.SetCurSel<m_list.GetCount<>-1>;}}voidCMp3Dlg::Onopen<>{ CStringstrfilename; intindex=m_list.GetCurSel<>; CStringmtime; CClientDCdc<this>; Mp3mp3; hour=0;minute=0;second=0; dc.SetBkColor<RGB<124,252,0>>;//設置放置計數器區域的外觀 dc.SetTextColor<RGB<255,255,203>>;//設置數字顯示的顏色 mtime.Format<"%02d:%02d:%02d",hour,minute,second>;//顯示時間進度 dc.TextOut<280,128,mtime>; if<index==-1> { MessageBox<"請添加音樂">; return; } m_list.GetText<index,strfilename>; SetDlgItemText<IDC_filename,strfilename>;mp3.Stop<>; mp3.Load<this->m_hWnd,strfilename>; mp3.Play<>;SetTimer<0,1000,NULL>;}voidCMp3Dlg::Onpause<>{ //TODO:Addyourcontrolnotificationhandlercodehere CStringstrtemp; Mp3mp3; GetDlgItemText<IDC_pause,strtemp>;//獲取按鈕狀態 if<strtemp.Compare<"暫停">==0> { mp3.Pause<>; SetDlgItemText<IDC_pause,"繼續">; KillTimer<0>;//取消計數器的顯示 } if<strtemp.Compare<"繼續">==0> { mp3.resum<>; SetTimer<0,1000,NULL>; SetDlgItemText<IDC_pause,"暫停">; }}voidCMp3Dlg::Onstop<>{ //TODO:Addyourcontrolnotificationhandlercodehere Mp3mp3; mp3.Stop<>; SetDlgItemText<IDC_pause,"暫停">; KillTimer<0>;//取消計數器的顯示 CStringmtime; CClientDCdc<this>; hour=0;minute=0;second=0; dc.SetBkColor<RGB<124,252,0>>;//設置放置計數器區域的外觀 dc.SetTextColor<RGB<255,255,203>>;//設置數字顯示的顏色 mtime.Format<"%02d:%02d:%02d",hour,minute,second>;//顯示時間進度 dc.TextOut<280,128,mtime>; GetDlgItem<IDC_open>->EnableWindow<FALSE>; GetDlgItem<IDC_pause>->EnableWindow<FALSE>; GetDlgItem<IDC_stop>->EnableWindow<FALSE>; GetDlgItem<IDC_del>->EnableWindow<FALSE>;}DWORDCMp3Dlg::Setvolumn<DWORDvol>{ MCI_DGV_SETAUDIO_PARMSmcisetvolumn; mcisetvolumn.dwCallback=NULL; mcisetvolumn.dwItem=MCI_DGV_SETAUDIO_VOLUME; mcisetvolumn.dwValue=vol;MCI_OPEN_PARMSmciopenparms; DWORDDeviceID; DeviceID=mciopenparms.wDeviceID; mciSendCommand<DeviceID,MCI_SETAUDIO,MCI_DGV_SETAUDIO_VALUE|MCI_DGV_SETAUDIO_ITEM,<DWORD><LPVOID>&mcisetvolumn>; // returnmcisetvolumn.dwValue; return0;}voidCMp3Dlg::OnReleasedcaptureSlider1<NMHDR*pNMHDR,LRESULT*pResult>{ //TODO:Addyourcontrolnotificationhandlercodehere Setvolumn<m_slider.GetPos<>>; *pResult=0;}voidCMp3Dlg::OnTimer<UINTnIDEvent>{ //TODO:Addyourmessagehandlercodehereand/orcalldefault CStringmtime; Mp3mp3; second++; CClientDCdc<this>; dc.SetBkColor<RGB<124,252,0>>;//設置放置計數器區域的外觀 dc.SetTextColor<RGB<255,255,203>>;//設置數字顯示的顏色if<second==60>//設置鐘表的顯示 { minute++;second=0; } if<minute==60> { hour++;minute=0; } mtime.Format<"%02d:%02d:%02d",hour,minute,second>;//顯示時間進度 dc.TextOut<280,128,mtime>; DWORDcdf=mp3.getinformation<MCI_STATUS_POSITION>; DWORDcdfrom; cdfrom=MCI_MAKE_MSF<MCI_MSF_MINUTE<cdf>,MCI_MSF_SECOND<cdf>,MCI_MSF_FRAME<cdf>>;//獲取當前播放文件的信息 UpdateData<false>; CDialog::OnTimer<nIDEvent>;}voidCMp3Dlg::Ondel<>{ UpdateData<TRUE>; Mp3mp3; intindex=m_list.GetCurSel<>; mp3.Stop<>; SetDlgItemText<IDC_filename,"">; KillTimer<0>; hour=0;minute=0;second=0;//歌曲時間置0 if<index!=CB_ERR> { m_list.DeleteString<index>; }}voidCMp3Dlg::OnDblclkList<>{ CStringmtime; Mp3mp3; CClientDCdc<this>; hour=0;minute=0;second=0; dc.SetBkColor<RGB<124,252,0>>;//設置放置計數器區域的外觀 dc.SetTextColor<RGB<255,255,203>>;//設置數字顯示的顏色 mtime.Format<"%02d:%02d:%02d",hour,minute,second>;//顯示時間進度 dc.TextOut<280,128,mtime>; CStringstrfilename; intindex=m_list.GetCurSel<>; m_list.GetText<index,strfilename>; SetDlgItemText<IDC_filename,strfilename>; mp3.Stop<>; mp3.Load<this->m_hWnd,strfilename>; mp3.Play<>;SetTimer<0,1000,NULL>; }mp3.cpp文件//Mp3.cpp:implementationoftheMp3class.////////////////////////////////////////////////////////////////////////#include"stdafx.h"#include"Mp3播放器.h"#include"Mp3.h"#ifdef_DEBUG#unde
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年03月國家藥品監督管理局直屬單位公開招聘126人筆試歷年典型考題(歷年真題考點)解題思路附帶答案詳解
- 武漢工程科技學院《篆刻1》2023-2024學年第二學期期末試卷
- 井下多功能測振儀項目安全評估報告
- 福建對外經濟貿易職業技術學院《圖片攝影》2023-2024學年第二學期期末試卷
- 山東藝術設計職業學院《西方戲劇選讀》2023-2024學年第二學期期末試卷
- 濮陽職業技術學院《色彩靜物及人物頭像》2023-2024學年第二學期期末試卷
- 年3D打印耗材項目安全評估報告
- 石家莊幼兒師范高等專科學校《美學與美育》2023-2024學年第一學期期末試卷
- 四川汽車職業技術學院《投資學》2023-2024學年第二學期期末試卷
- 河北政法職業學院《小學英語教學設計》2023-2024學年第二學期期末試卷
- 新型電力系統簡介演示
- 醫療機構風險評估報告
- 2022年工程機械設備租賃服務方案(含應急處理方案、保障措施)
- 加工工藝改善表
- 10月份企業網上銀行電子回單
- 國家開放大學畢業生登記表-
- 豐華醫院放射治療室安全管理制度
- 【公司利潤質量研究國內外文獻綜述3400字】
- 人力資源管理(黑龍江聯盟)知到章節答案智慧樹2023年哈爾濱師范大學
- 學生班級衛生值日表模板下載
- 拒絕內耗做自己-高中主題班會
評論
0/150
提交評論