手把手教您用mfc做mp3音乐播放器

上传人:kms****20 文档编号:40365228 上传时间:2018-05-26 格式:DOC 页数:29 大小:568.50KB
返回 下载 相关 举报
手把手教您用mfc做mp3音乐播放器_第1页
第1页 / 共29页
手把手教您用mfc做mp3音乐播放器_第2页
第2页 / 共29页
手把手教您用mfc做mp3音乐播放器_第3页
第3页 / 共29页
手把手教您用mfc做mp3音乐播放器_第4页
第4页 / 共29页
手把手教您用mfc做mp3音乐播放器_第5页
第5页 / 共29页
点击查看更多>>
资源描述

《手把手教您用mfc做mp3音乐播放器》由会员分享,可在线阅读,更多相关《手把手教您用mfc做mp3音乐播放器(29页珍藏版)》请在金锄头文库上搜索。

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:OnPai

2、nt() if (IsIconic() CPaintDC dc(this); / device context for paintingSendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);/ Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect( int x = (rect.Width() - cxI

3、con + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2;/ Draw the icon dc.DrawIcon(x, y, m_hIcon); else /CDialog:OnPaint(); CPaintDC dc(this); CRect rect; GetClientRect( CDC dcMem; dcMem.CreateCompatibleDC( CBitmap bmpBackground; bmpBackground.LoadBitmap(IDB_BITMAP6); /IDB_BITMAP6 是你的位图地址 BITMAP bit

4、map; bmpBackground.GetBitmap( CBitmap *pbmpOld=dcMem.SelectObject( dc.StretchBlt(0,0,rect.Width(),rect.Height(), 编译运行,你就会看到背景有图片了。 插入-类,找到 geneticclass,类名 mp3.cpp你会发现在头文件中多了一个 mp3.h 文件在 mp3.h 文件中添加代码如下 / Mp3.h: interface for the Mp3 class. / /#if !defined(AFX_MP3_H_20D325E5_A96A_43FE_A485_92F57C68DD

5、0D_INCLUDED_) #define AFX_MP3_H_20D325E5_A96A_43FE_A485_92F57C68DD0D_INCLUDED_#if _MSC_VER 1000 #pragma once #endif / _MSC_VER 1000 #include “Mmsystem.h“class Mp3 public: Mp3(); virtual Mp3();HWND m_hWnd; / DWORD DeviceID;/IDMCI_OPEN_PARMS mciopenparms; /void Load(HWND hwnd,CString Strfilepath); DWO

6、RD 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.h“#ifdef _DEBUG #undef

7、THIS_FILE static 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=mciSendCo

8、mmand(NULL,MCI_OPEN,MCI_OPEN_ELEMENT|MCI_WAIT,(DWORD)(LPV OID) mciGetErrorString(dwReturn,buffer,256);MessageBox(hwnd,buffer,“,MB_ICONHAND|MB_ICONERROR|MB_ICONSTOP); DeviceID=mciopenparms.wDeviceID; / DWORD Mp3:getinformation(DWORD item) /MCI MCI_STATUS_PARMS mcistatusparms; / mcistatusparms.dwItem=

9、item; mcistatusparms.dwReturn=0; / mciSendCommand(DeviceID,MCI_STATUS,MCI_STATUS_ITEM,(DWORD) return mcistatusparms.dwReturn; void Mp3:Play() MCI_PLAY_PARMS mciplayparms;mciplayparms.dwCallback=(DWORD)m_hWnd; mciplayparms.dwFrom=0; / mciSendCommand(DeviceID,MCI_PLAY,MCI_FROM|MCI_NOTIFY,(DWORD)(LPVOI

10、D) 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,minute,second; 在 CMp3Dlg:CMp3Dlg(CWnd* pParent /*

11、=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 Win32 m_hIcon = AfxGetApp()-LoadIcon(IDI_ICON1); hour=0;minute=0;second=0; dlg.cpp 中头文件如下: #inclu

12、de “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_FILE static char THIS_FILE = _FILE_; #endif在对话框中双击添加添加 onfileopen 函数,代码如下 void CMp3Dlg:Onfileopen() char

13、filefiler=“mp3 文件(*.mp3)|*.mp3|“wma 文件(*.wma)|*.wma|“wav 文件(*.wav)|*.wav|“; CFileDialog dlg(true,NULL,NULL,OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT|OFN_ENABLESIZING,filefile r); if (dlg.DoModal()=IDOK) CString strfilepath=dlg.GetPathName(); CString strfilename=dlg.GetFileName(); SetDlgItemText(IDC_file

14、name,strfilename); CString mtime; CClientDC dc(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); Mp3 mp3; mp3.Load(this-m_hWnd,strfilepath); GetDlgItem(IDC_open)-EnableWindow(TRUE); GetDlgItem(IDC_pause)-EnableWindow(TRUE); GetDlgItem(IDC

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号