版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
./第一步:打开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;//Ö¸¶¨²¥·ÅÒôÀÖµÄÉ豸IDMCI_OPEN_PARMSmciopenparms;//Ö¸¶¨´ò¿ªÒôÀÖÎļþµÄ²ÎÊývoidLoad<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"Mp3²¥·ÅÆ÷.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>;//¼ÓÔØÎļþÇ°ÏÈÇå³ýÉÏ´ÎÉèÖà mciopenparms.lpstrElementName=Strfilepath;//½«ÒôÀÖÎļþ·¾¶´«¸øÉ豸 DWORDdwReturn; if<dwReturn=mciSendCommand<NULL,MCI_OPEN,MCI_OPEN_ELEMENT|MCI_WAIT,<DWORD><LPVOID>&mciopenparms>> { //Èç¹û´ò¿ªÊ§°Ü£¬½«³ö´íÐÅÏ¢´æÔÚbuffer²¢ÏÔʾ³ö´í¾¯¸æ charbuffer[256]; mciGetErrorString<dwReturn,buffer,256>; MessageBox<hwnd,buffer,"³ö´í¾¯¸æ",MB_ICONHAND|MB_ICONERROR|MB_ICONSTOP>; } DeviceID=mciopenparms.wDeviceID;//¶àýÌåÉ豸ÀàÐͱàºÅ}DWORDMp3::getinformation<DWORDitem>{ //MCI½Ó¿Ú¶ÔÏóµÄ״̬ MCI_STATUS_PARMSmcistatusparms; //´ý»ñÈ¡µÄÏîÄ¿ mcistatusparms.dwItem=item; mcistatusparms.dwReturn=0; //Ïë¶àýÌåÉ豸·¢ËÍÖ¸Á»ñÈ¡µ±Ç°µÄ״̬²ÎÊý mciSendCommand<DeviceID,MCI_STATUS,MCI_STATUS_ITEM,<DWORD>&mcistatusparms>; returnmcistatusparms.dwReturn;}voidMp3::Play<>{ MCI_PLAY_PARMSmciplayparms; mciplayparms.dwCallback=<DWORD>m_hWnd; mciplayparms.dwFrom=0;//ÿ´Î´ÓÍ·²¥·Å 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"Mp3²¥·ÅÆ÷.h"#include"Mp3²¥·ÅÆ÷Dlg.h"#include"Mmsystem.h"#include"Digitalv.h"#include"Mp3.h"//ÒôÁ¿¿ØÖÆÓõ½#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"//音量控制用到#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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 全球企业知识产权创新调研报告
- 基层护理安全管理
- 《复杂结构的计算》课件
- 冠心病药物治疗原则
- 《光辐射探测器》课件2
- 《安全生产法解读》课件
- 3年级数学下册课件
- 大班美术活动:奔跑的小马
- 公交职业道德培训
- 2025高考数学专项复习第三章 函数与基本初等函数第4节 幂函数与二次函数含答案
- 2023年英语专业四级单选题汇总
- GB/T 451.3-2002纸和纸板厚度的测定
- GB/T 31548-2015电动自行车轮胎系列
- GB/T 21661-2020塑料购物袋
- GB/T 14480.1-2015无损检测仪器涡流检测设备第1部分:仪器性能和检验
- 《 小二黑结婚 》课件-统编版高中语文选择性必修中册
- FZ/T 21001-2019自梳外毛毛条
- CB/T 3780-1997管子吊架
- 四川省阿坝藏族羌族自治州《综合知识》事业单位国考真题
- 2023年人民法院电子音像出版社招聘笔试题库及答案解析
- 采购合同采购合同采购合同
评论
0/150
提交评论