版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、打開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函數下添加代碼void cmp3dlg:onpaint() if (isiconic()cp
2、aintdc dc(this); / device context for paintingsendmessage(wm_iconerasebkgnd, (wparam) dc.getsafehdc(), 0);/ center icon in client rectangleint cxicon = getsystemmetrics(sm_cxicon);int cyicon = getsystemmetrics(sm_cyicon);crect rect;getclientrect(&rect);int x = (rect.width() - cxicon + 1) / 2;int y =
3、 (rect.height() - cyicon + 1) / 2;/ draw the icondc.drawicon(x, y, m_hicon);else/cdialog:onpaint();cpaintdc dc(this); crect rect; getclientrect(&rect); cdc dcmem; dcmem.createcompatibledc(&dc); cbitmap bmpbackground; bmpbackground.loadbitmap(idb_bitmap6); /idb_bitmap6是你的位圖地址bitmap bitmap; bmpbackgro
4、und.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你會發(fā)現在頭文件中多了一個mp3.h文件在mp3.h文件中添加代碼如下/ mp3.h: interface for the mp3 class./#if !de
5、fined(afx_mp3_h_20d325e5_a96a_43fe_a485_92f57c68dd0d_included_)#define afx_mp3_h_20d325e5_a96a_43fe_a485_92f57c68dd0d_included_#if _msc_ver 1000#pragma once#endif / _msc_ver 1000#include mmsystem.hclass mp3 public:mp3();virtual mp3(); hwnd m_hwnd; /dword deviceid;/id mci_open_parms mciopenparms; / v
6、oid load(hwnd hwnd,cstring strfilepath);dword getinformation(dword item);void play();void pause();void resum();void stop();#endif / !defined(afx_mp3_h_20d325e5_a96a_43fe_a485_92f57c68dd0d_included_)在mp3.cpp中添加如下代碼/ mp3.cpp: implementation of the mp3 class./#include stdafx.h#include mp3.h#include mp3
7、.h#ifdef _debug#undef this_filestatic char this_file=_file_;#define new debug_new#endif/ construction/destruction/mp3:mp3()mp3:mp3()void mp3:load(hwnd hwnd,cstring strfilepath)m_hwnd=hwnd;mcisendcommand(deviceid,mci_close,0,0); /mciopenparms.lpstrelementname=strfilepath;/dword dwreturn;if (dwreturn=
8、mcisendcommand(null,mci_open,mci_open_element|mci_wait,(dword)(lpvoid)&mciopenparms)/bufferchar buffer256; mcigeterrorstring(dwreturn,buffer,256);messagebox(hwnd,buffer,mb_iconhand|mb_iconerror|mb_iconstop);deviceid=mciopenparms.wdeviceid; /dword mp3:getinformation(dword item)/mcimci_status_parms mc
9、istatusparms;/mcistatusparms.dwitem=item;mcistatusparms.dwreturn=0;/mcisendcommand(deviceid,mci_status,mci_status_item,(dword)&mcistatusparms);return mcistatusparms.dwreturn; void mp3:play()mci_play_parms mciplayparms;mciplayparms.dwcallback=(dword)m_hwnd;mciplayparms.dwfrom=0; /mcisendcommand(devic
10、eid,mci_play,mci_from|mci_notify,(dword)(lpvoid)&mciplayparms);void mp3:pause()mcisendcommand(deviceid,mci_pause,0,0);void mp3:resum()mcisendcommand(deviceid,mci_resume,0,0);void mp3:stop()mcisendcommand(deviceid,mci_stop,0,0);mcisendcommand(deviceid,mci_close,0,0);在dlg.cpp文件的public中添加一行代碼:int hour,
11、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/ note that loadicon does not require a subsequent destroyicon in win32m_hicon = afxgetapp()-loadicon(idi_icon1);hour=0;mi
12、nute=0;second=0;dlg.cpp中頭文件如下:#include stdafx.h#include mp3.h#include mp3dlg.h#include mmsystem.h#include digitalv.h #include mp3.h /#pragma comment(lib,winmm.lib)#ifdef _debug#define new debug_new#undef this_filestatic char this_file = _file_;#endif在對話框中雙擊添加添加onfileopen函數,代碼如下void cmp3dlg:onfileope
13、n() char filefiler=mp3文件(*.mp3)|*.mp3| wma文件(*.wma)|*.wma| wav文件(*.wav)|*.wav|;cfiledialog dlg(true,null,null,ofn_hidereadonly|ofn_allowmultiselect|ofn_enablesizing,filefiler);if (dlg.domodal()=idok)cstring strfilepath=dlg.getpathname();cstring strfilename=dlg.getfilename();setdlgitemtext(idc_filena
14、me,strfilename);cstring mtime;cclientdc dc(this);hour=0;minute=0;second=0;dc.setbkcolor(rgb(124,252,0);/設置放置計數器區(qū)域的外觀dc.settextcolor(rgb(255,255,203);/設置數字顯示的顏色mtime.format(%02d:%02d:%02d,hour,minute,second);/顯示時間進度dc.textout(280,128,mtime);mp3 mp3;mp3.load(this-m_hwnd,strfilepath);getdlgitem(idc_ope
15、n)-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);雙擊播放,進入代碼,添加如下void cmp3dlg:onopen() cstring strfilename;int i
16、ndex=m_list.getcursel();cstring mtime;cclientdc dc(this);mp3 mp3;hour=0;minute=0;second=0;dc.setbkcolor(rgb(124,252,0);/設置放置計數器區(qū)域的外觀dc.settextcolor(rgb(255,255,203);/設置數字顯示的顏色mtime.format(%02d:%02d:%02d,hour,minute,second);/顯示時間進度dc.textout(280,128,mtime);if(index=-1)messagebox(請?zhí)砑右魳?;return;m_list.
17、gettext(index,strfilename);setdlgitemtext(idc_filename,strfilename); mp3.stop();mp3.load(this-m_hwnd,strfilename);mp3.play(); settimer(0,1000,null);同理,暫停,停止,刪除,退出代碼如下void cmp3dlg:onpause() / todo: add your control notification handler code herecstring strtemp;mp3 mp3;getdlgitemtext(idc_pause,strtemp
18、);/獲取按鈕狀態(tài)if (strtemp.compare(暫停)=0)mp3.pause();setdlgitemtext(idc_pause,繼續(xù));killtimer(0);/取消計數器的顯示if (strtemp.compare(繼續(xù))=0)mp3.resum();settimer(0,1000,null);setdlgitemtext(idc_pause,暫停);void cmp3dlg:onstop() / todo: add your control notification handler code heremp3 mp3;mp3.stop();setdlgitemtext(id
19、c_pause,暫停);killtimer(0);/取消計數器的顯示cstring mtime;cclientdc dc(this);hour=0;minute=0;second=0;dc.setbkcolor(rgb(124,252,0);/設置放置計數器區(qū)域的外觀dc.settextcolor(rgb(255,255,203);/設置數字顯示的顏色mtime.format(%02d:%02d:%02d,hour,minute,second);/顯示時間進度dc.textout(280,128,mtime);getdlgitem(idc_open)-enablewindow(false);g
20、etdlgitem(idc_pause)-enablewindow(false);getdlgitem(idc_stop)-enablewindow(false); getdlgitem(idc_del)-enablewindow(false);void cmp3dlg:ondel() updatedata(true);mp3 mp3;int index=m_list.getcursel();mp3.stop();setdlgitemtext(idc_filename,);killtimer(0);hour=0;minute=0;second=0;/歌曲時間置0if (index!=cb_er
21、r)m_list.deletestring(index);void cmp3dlg:onexit() / todo: add your control notification handler code herecdialog:oncancel();ctrl+w打開類向導,如圖,添加ontimer函數代碼如下:void cmp3dlg:ontimer(uint nidevent) / todo: add your message handler code here and/or call defaultcstring mtime;mp3 mp3;second+;cclientdc dc(thi
22、s);dc.setbkcolor(rgb(124,252,0);/設置放置計數器區(qū)域的外觀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); dword cdf=mp3.getinformation(mci_status_position);dword cdfrom;
23、 cdfrom=mci_make_msf(mci_msf_minute(cdf),mci_msf_second(cdf),mci_msf_frame(cdf);/獲取當前播放文件的信息updatedata(false);cdialog:ontimer(nidevent);ctrl+w打開類向導添加函數如下void cmp3dlg:ondblclklist() /在列表中選中,雙擊左鍵播放音樂cstring mtime;mp3 mp3;cclientdc dc(this);hour=0;minute=0;second=0;dc.setbkcolor(rgb(124,252,0);/設置放置計數器
24、區(qū)域的外觀dc.settextcolor(rgb(255,255,203);/設置數字顯示的顏色mtime.format(%02d:%02d:%02d,hour,minute,second);/顯示時間進度dc.textout(280,128,mtime);cstring strfilename;int index=m_list.getcursel();m_list.gettext(index,strfilename);setdlgitemtext(idc_filename,strfilename);mp3.stop();mp3.load(this-m_hwnd,strfilename);mp
25、3.play(); settimer(0,1000,null);打開類向導,添加函數如下void cmp3dlg:oncustomdrawslider1(nmhdr* pnmhdr, lresult* presult) / todo: add your control notification handler code hereupdatedata(true);m_int=m_slider.getpos()/10;setvolumn(m_slider.getpos();updatedata(false);*presult = 0;打開類向導,添加函數如下void cmp3dlg:onrelea
26、sedcaptureslider1(nmhdr* pnmhdr, lresult* presult) / todo: add your control notification handler code heresetvolumn(m_slider.getpos();*presult = 0;添加聲音設置函數如下dword cmp3dlg:setvolumn(dword vol)mci_dgv_setaudio_parms mcisetvolumn;mcisetvolumn.dwcallback=null;mcisetvolumn.dwitem=mci_dgv_setaudio_volume;
27、mcisetvolumn.dwvalue=vol; mci_open_parms mciopenparms;dword deviceid;deviceid=mciopenparms.wdeviceid;mcisendcommand(deviceid,mci_setaudio,mci_dgv_setaudio_value|mci_dgv_setaudio_item,(dword)(lpvoid)&mcisetvolumn);/return mcisetvolumn.dwvalue;return 0;到此已經基本完成了,我們可以試聽一下接下來我們可以到包成exe可執(zhí)行文件,為了去掉那個不好看的圖標
28、,我們可以進入res文件夾,把原來的圖標刪掉,不過,你要放入一個cio格式的圖片作為圖標,cio格式網上有很多轉換的,刪掉原圖標后,程序會自動生成一個你放進去的圖標。接下來演示打包:工程,設置,或者按alt+f7,如圖設置組建,批組建,如圖創(chuàng)建完成后,你就會發(fā)現在你的工程文件中多了一個release文件夾,打開找到exe,這個文件就是打包好的,隨便放到哪里都可以執(zhí)行,至此,工作基本完成了,最后附上源代碼,僅供參考dlg.cpp文件/ mp3播放器dlg.cpp : implementation file/#include stdafx.h#include mp3播放器.h#include mp
29、3播放器dlg.h#include mmsystem.h#include digitalv.h #include mp3.h /音量控制用到#pragma comment(lib,winmm.lib)#ifdef _debug#define new debug_new#undef this_filestatic char this_file = _file_;#endif/ caboutdlg dialog used for app aboutclass caboutdlg : public cdialogpublic:caboutdlg();/ dialog data/afx_data(ca
30、boutdlg)enum idd = idd_aboutbox ;/afx_data/ classwizard generated virtual function overrides/afx_virtual(caboutdlg)protected:virtual void dodataexchange(cdataexchange* pdx); / ddx/ddv support/afx_virtual/ implementationprotected:/afx_msg(caboutdlg)/afx_msgdeclare_message_map();caboutdlg:caboutdlg()
31、: cdialog(caboutdlg:idd)/afx_data_init(caboutdlg)/afx_data_initvoid caboutdlg:dodataexchange(cdataexchange* pdx)cdialog:dodataexchange(pdx);/afx_data_map(caboutdlg)/afx_data_mapbegin_message_map(caboutdlg, cdialog)/afx_msg_map(caboutdlg)/ no message handlers/afx_msg_mapend_message_map()/ cmp3dlg dia
32、logcmp3dlg:cmp3dlg(cwnd* pparent /*=null*/): cdialog(cmp3dlg:idd, pparent)/afx_data_init(cmp3dlg)m_int = 0;/afx_data_init/ note that loadicon does not require a subsequent destroyicon in win32m_hicon = afxgetapp()-loadicon(idi_icon1);hour=0;minute=0;second=0;void cmp3dlg:dodataexchange(cdataexchange
33、* 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_mapbegin_message_map(cmp3dlg, cdialog)/afx_msg_map(cmp3dlg)on_wm_syscommand()on_wm_paint()on_wm_querydragicon()on_bn_clicked(id_e
34、xit, 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(i
35、dc_del, ondel)on_lbn_dblclk(idc_list, ondblclklist)/afx_msg_mapend_message_map()/ cmp3dlg message handlersbool cmp3dlg:oninitdialog()cdialog:oninitdialog();/ add about. menu item to system menu./ idm_aboutbox must be in the system command range.assert(idm_aboutbox & 0xfff0) = idm_aboutbox);assert(id
36、m_aboutbox appendmenu(mf_separator);psysmenu-appendmenu(mf_string, idm_aboutbox, straboutmenu);/ set the icon for this dialog. the framework does this automatically/ when the applications main window is not a dialogseticon(m_hicon, true);/ set big iconseticon(m_hicon, false); / set small iconsetwind
37、owtext(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: add extra ini
38、tialization herereturn true; / return true unless you set the focus to a controlvoid cmp3dlg:onsyscommand(uint nid, lparam lparam)if (nid & 0xfff0) = idm_aboutbox)caboutdlg dlgabout;dlgabout.domodal();elsecdialog:onsyscommand(nid, lparam);/ if you add a minimize button to your dialog, you will need
39、the code below/ to draw the icon. for mfc applications using the document/view model,/ this is automatically done for you by the framework.void cmp3dlg:onpaint() if (isiconic()cpaintdc dc(this); / device context for paintingsendmessage(wm_iconerasebkgnd, (wparam) dc.getsafehdc(), 0);/ center icon in
40、 client rectangleint cxicon = getsystemmetrics(sm_cxicon);int cyicon = getsystemmetrics(sm_cyicon);crect rect;getclientrect(&rect);int x = (rect.width() - cxicon + 1) / 2;int y = (rect.height() - cyicon + 1) / 2;/ draw the icondc.drawicon(x, y, m_hicon);else/cdialog:onpaint();cpaintdc dc(this); crec
41、t rect; getclientrect(&rect); cdc dcmem; dcmem.createcompatibledc(&dc); cbitmap bmpbackground; bmpbackground.loadbitmap(idb_bitmap6); bitmap bitmap; bmpbackground.getbitmap(&bitmap); cbitmap *pbmpold=dcmem.selectobject(&bmpbackground); dc.stretchblt(0,0,rect.width(),rect.height(),&dcmem,0,0,bitmap.b
42、mwidth,bitmap.bmheight,srccopy); / the system calls this to obtain the cursor to display while the user drags/ the minimized window.hcursor cmp3dlg:onquerydragicon()return (hcursor) m_hicon;void cmp3dlg:onexit() / todo: add your control notification handler code herecdialog:oncancel();void cmp3dlg:o
43、ncustomdrawslider1(nmhdr* pnmhdr, lresult* presult) / todo: add your control notification handler code hereupdatedata(true);m_int=m_slider.getpos()/10;setvolumn(m_slider.getpos();updatedata(false);*presult = 0;void cmp3dlg:onfileopen() char filefiler=mp3文件(*.mp3)|*.mp3| wma文件(*.wma)|*.wma| wav文件(*.w
44、av)|*.wav|;cfiledialog dlg(true,null,null,ofn_hidereadonly|ofn_allowmultiselect|ofn_enablesizing,filefiler);if (dlg.domodal()=idok)cstring strfilepath=dlg.getpathname();cstring strfilename=dlg.getfilename();setdlgitemtext(idc_filename,strfilename);cstring mtime;cclientdc dc(this);hour=0;minute=0;sec
45、ond=0;dc.setbkcolor(rgb(124,252,0);/設置放置計數器區(qū)域的外觀dc.settextcolor(rgb(255,255,203);/設置數字顯示的顏色mtime.format(%02d:%02d:%02d,hour,minute,second);/顯示時間進度dc.textout(280,128,mtime);mp3 mp3;mp3.load(this-m_hwnd,strfilepath);getdlgitem(idc_open)-enablewindow(true);getdlgitem(idc_pause)-enablewindow(true);getdl
46、gitem(idc_stop)-enablewindow(true);getdlgitem(idc_del)-enablewindow(true); m_list.insertstring(m_list.getcount(),strfilename);/獲取文件名 m_list.setcursel(m_list.getcount()-1);void cmp3dlg:onopen() cstring strfilename;int index=m_list.getcursel();cstring mtime;cclientdc dc(this);mp3 mp3;hour=0;minute=0;s
47、econd=0;dc.setbkcolor(rgb(124,252,0);/設置放置計數器區(qū)域的外觀dc.settextcolor(rgb(255,255,203);/設置數字顯示的顏色mtime.format(%02d:%02d:%02d,hour,minute,second);/顯示時間進度dc.textout(280,128,mtime);if(index=-1)messagebox(請?zhí)砑右魳?;return;m_list.gettext(index,strfilename);setdlgitemtext(idc_filename,strfilename); mp3.stop();mp
48、3.load(this-m_hwnd,strfilename);mp3.play(); settimer(0,1000,null);void cmp3dlg:onpause() / todo: add your control notification handler code herecstring strtemp;mp3 mp3;getdlgitemtext(idc_pause,strtemp);/獲取按鈕狀態(tài)if (strtemp.compare(暫停)=0)mp3.pause();setdlgitemtext(idc_pause,繼續(xù));killtimer(0);/取消計數器的顯示if (strtemp.compare(繼續(xù))=0)mp3.resum();settimer(0,1000,null);setdlgitemtext(idc_pause,暫停);void cmp3dlg:onstop() / todo: add your control notification handler code heremp3
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 班主任心理健康與壓力管理的培訓總結
- 公交掃惡除霸承諾書范本
- 2025-2030全球船用防火窗行業(yè)調研及趨勢分析報告
- 2025年全球及中國運動刺激療法行業(yè)頭部企業(yè)市場占有率及排名調研報告
- 2025年全球及中國矩形橋式起重機行業(yè)頭部企業(yè)市場占有率及排名調研報告
- 2025-2030全球便攜式鼻腔沖洗器行業(yè)調研及趨勢分析報告
- 2025-2030全球農用氧化亞銅行業(yè)調研及趨勢分析報告
- 2025年全球及中國鋼制螺旋錐齒輪行業(yè)頭部企業(yè)市場占有率及排名調研報告
- 2025年全球及中國戶外電氣箱行業(yè)頭部企業(yè)市場占有率及排名調研報告
- 2025-2030全球軸承精密滾珠行業(yè)調研及趨勢分析報告
- 蛋糕店服務員勞動合同
- 土地買賣合同參考模板
- 2025高考數學二輪復習-專題一-微專題10-同構函數問題-專項訓練【含答案】
- 2025年天津市政建設集團招聘筆試參考題庫含答案解析
- 2024-2030年中國烘焙食品行業(yè)運營效益及營銷前景預測報告
- 2025年上半年水利部長江水利委員會事業(yè)單位招聘68人(湖北武漢)重點基礎提升(共500題)附帶答案詳解
- 寧德時代筆試題庫
- 五年級下冊北京版英語單詞
- 康復醫(yī)院患者隱私保護管理制度
- 新課標I、Ⅱ卷 (2024-2020) 近五年高考英語真題滿分作文
- 浙江省嘉興市2023-2024學年六年級(上)期末數學試卷
評論
0/150
提交評論