音乐播放器源代码

/******做着玩的,很简易,有打开,播放,暂停,退出等功能,只能播放本地音乐,没有实现联网功能,支持wav格式和MP3。*******/

MusicPlayerDlg.cpp:

// MusicPlayerDlg.cpp : implementation file
//#include "stdafx.h"
#include "MusicPlayer.h"
#include "MusicPlayerDlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/
// CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog
{
public:CAboutDlg();// Dialog Data//{{AFX_DATA(CAboutDlg)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// Implementation
protected://{{AFX_MSG(CAboutDlg)//}}AFX_MSGDECLARE_MESSAGE_MAP()
};CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{//{{AFX_DATA_INIT(CAboutDlg)//}}AFX_DATA_INIT
}void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CAboutDlg)//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)//{{AFX_MSG_MAP(CAboutDlg)// No message handlers//}}AFX_MSG_MAP
END_MESSAGE_MAP()/
// CMusicPlayerDlg dialogCMusicPlayerDlg::CMusicPlayerDlg(CWnd* pParent /*=NULL*/): CDialog(CMusicPlayerDlg::IDD, pParent)
{//{{AFX_DATA_INIT(CMusicPlayerDlg)m_TextFilePath = _T("");//}}AFX_DATA_INIT// Note that LoadIcon does not require a subsequent DestroyIcon in Win32m_hIcon = AfxGetApp()->LoadIcon(IDI_Music);
}void CMusicPlayerDlg::DoDataExchange(CDataExchange* pDX)
{CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CMusicPlayerDlg)DDX_Text(pDX, IDC_EDIT2, m_TextFilePath);DDV_MaxChars(pDX, m_TextFilePath, 100);//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CMusicPlayerDlg, CDialog)//{{AFX_MSG_MAP(CMusicPlayerDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BTN_OPEN, OnBtnOpen)ON_BN_CLICKED(IDC_BTN_PLAY, OnBtnPlay)ON_BN_CLICKED(IDC_BTN_PAUSE, OnBtnPause)ON_BN_CLICKED(IDC_BTN_STOP, OnBtnStop)ON_BN_CLICKED(IDC_BTN_HELP, OnBtnHelp)//}}AFX_MSG_MAP
END_MESSAGE_MAP()/
// CMusicPlayerDlg message handlersBOOL CMusicPlayerDlg::OnInitDialog()
{CDialog::OnInitDialog();// Add "About..." menu item to system menu.PlaySound("C:\\Users\\Administrator\\Desktop\\Audio.wav",NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);// IDM_ABOUTBOX must be in the system command range.ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX < 0xF000);CMenu* pSysMenu = GetSystemMenu(FALSE);if (pSysMenu != NULL){CString strAboutMenu;strAboutMenu.LoadString(IDS_ABOUTBOX);if (!strAboutMenu.IsEmpty()){pSysMenu->AppendMenu(MF_SEPARATOR);pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);}}// Set the icon for this dialog.  The framework does this automatically//  when the application's main window is not a dialogSetIcon(m_hIcon, TRUE);           // Set big iconSetIcon(m_hIcon, FALSE);     // Set small icon// TODO: Add extra initialization herereturn TRUE;  // return TRUE  unless you set the focus to a control
}void CMusicPlayerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{if ((nID & 0xFFF0) == IDM_ABOUTBOX){CAboutDlg dlgAbout;dlgAbout.DoModal();}else{CDialog::OnSysCommand(nID, lParam);}
}// If you add a minimize button to your dialog, you will need 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 CMusicPlayerDlg::OnPaint()
{if (IsIconic()){CPaintDC 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 = (rect.Height() - cyIcon + 1) / 2;// Draw the icondc.DrawIcon(x, y, m_hIcon);}else{CDialog::OnPaint();}
}// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMusicPlayerDlg::OnQueryDragIcon()
{return (HCURSOR) m_hIcon;
}void CMusicPlayerDlg::OnBtnOpen()
{// TODO: Add your control notification handler code hereCFileDialog dig(TRUE,NULL,NULL,OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST,"mp3文件(*MP3)|*.mp3|wav文件(*wav)|*.wav|所有文件(*.*)|*.*||");if(IDCANCEL==dig.DoModal())return;CString strFilePath=dig.GetPathName();SetDlgItemText(IDC_EDIT2,strFilePath);mciSendCommand(m_IDdevice,MCI_CLOSE,0,0);//打开一首歌曲MCI_OPEN_PARMS mciOpenParms;mciOpenParms.lpstrElementName=strFilePath;//MessageBox(strFilePath);mciSendCommand(NULL,MCI_OPEN,MCI_OPEN_ELEMENT|MCI_WAIT,(DWORD)&mciOpenParms);m_IDdevice=mciOpenParms.wDeviceID;
}void CMusicPlayerDlg::OnBtnPlay()
{// TODO: Add your control notification handler code hereMCI_PLAY_PARMS mciPlayParms;mciPlayParms.dwCallback=NULL;mciPlayParms.dwFrom=0;mciSendCommand(m_IDdevice,MCI_PLAY,MCI_FROM|MCI_NOTIFY,(DWORD)&mciPlayParms);}void CMusicPlayerDlg::OnBtnPause()
{// TODO: Add your control notification handler code hereCString str;GetDlgItemText(IDC_BTN_PAUSE,str);if(str=="暂停"){   mciSendCommand(m_IDdevice, MCI_PAUSE,0,0);SetDlgItemText(IDC_BTN_PAUSE,"继续");}else{mciSendCommand(m_IDdevice, MCI_RESUME,0,0);SetDlgItemText(IDC_BTN_PAUSE,"暂停");}
}void CMusicPlayerDlg::OnBtnStop()
{// TODO: Add your control notification handler code hereSetDlgItemText(IDC_EDIT2,"");mciSendCommand(m_IDdevice,MCI_STOP,0,0);mciSendCommand(m_IDdevice,MCI_CLOSE,0,0);}void CMusicPlayerDlg::OnBtnHelp()
{// TODO: Add your control notification handler code hereCAboutDlg dlgAbout;dlgAbout.DoModal();}

MusicPlayer.cpp:

// MusicPlayer.cpp : Defines the class behaviors for the application.
//#include "stdafx.h"
#include "MusicPlayer.h"
#include "MusicPlayerDlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/
// CMusicPlayerAppBEGIN_MESSAGE_MAP(CMusicPlayerApp, CWinApp)//{{AFX_MSG_MAP(CMusicPlayerApp)// NOTE - the ClassWizard will add and remove mapping macros here.//    DO NOT EDIT what you see in these blocks of generated code!//}}AFX_MSGON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()/
// CMusicPlayerApp constructionCMusicPlayerApp::CMusicPlayerApp()
{// TODO: add construction code here,// Place all significant initialization in InitInstance
}/
// The one and only CMusicPlayerApp objectCMusicPlayerApp theApp;/
// CMusicPlayerApp initializationBOOL CMusicPlayerApp::InitInstance()
{AfxEnableControlContainer();// Standard initialization// If you are not using these features and wish to reduce the size//  of your final executable, you should remove from the following//  the specific initialization routines you do not need.#ifdef _AFXDLLEnable3dControls();           // Call this when using MFC in a shared DLL
#elseEnable3dControlsStatic();  // Call this when linking to MFC statically
#endifCMusicPlayerDlg dlg;m_pMainWnd = &dlg;int nResponse = dlg.DoModal();if (nResponse == IDOK){// TODO: Place code here to handle when the dialog is//  dismissed with OK}else if (nResponse == IDCANCEL){// TODO: Place code here to handle when the dialog is//  dismissed with Cancel}// Since the dialog has been closed, return FALSE so that we exit the//  application, rather than start the application's message pump.return FALSE;
}

程序运行截图:

做的很简易,只为了解,学习,记录,共享之用

如需下载程序,我给网盘:链接: http://pan.baidu.com/s/1nuKkyM1 密码: wxvk
                       
                                      联系邮箱:xhsgg12302@outlook.com

2016_12_30

MFC简易音乐播放器相关推荐

  1. JavaScript + Audio API自制简易音乐播放器(详细完整版、小白都能看懂)

    JavaScript + Audio API自制简易音乐播放器(详细完整版) ** 音乐播放器的功能清单如下: ** 1.点击暂停按钮,歌曲暂停 2.点击播放按钮,歌曲播放 3.单曲循环与取消单曲循环 ...

  2. html实现简易音乐播放器

    目标: 使用vue.js导包的形式做一个简单的音乐播放器,新手也很容易看懂. 内容: 1. 使用了flex实现响应式布局: 2. 使用min-width防止字体被压缩: 3. 使用computed计算 ...

  3. Android Studio简易音乐播放器设计作业

    Android Studio简易音乐播放器设计作业 实验成功展示 实验代码 MainActivity.java XML文件 class文件 利用BroadcastReceiver模拟音乐播放器,实现播 ...

  4. 单片机音乐播放器课程设计C语言,单片机课程设计简易音乐播放器

    单片机课程设计简易音乐播放器 论文题目:简易音乐播放器所属系部:电子工程系 指导教师: 学生姓名: 学 号: 专 业: 电子信息工程技术 题目: 简易音乐播放器任务与要求:本设计以 MCS-51 系列 ...

  5. 【毕业设计】28-基于单片机的音乐播放器简易音乐播放器设计(原理图+源代码+仿真工程+答辩PPT+答辩论文)

    typora-root-url: ./ [毕业设计]28-基于单片机的音乐播放器简易音乐播放器设计(原理图+源代码+仿真工程+答辩PPT+答辩论文) 文章目录 typora-root-url: ./ ...

  6. 【微信小程序】简易音乐播放器,进度条拖拉、音乐的播放与暂停

    小程序简易音乐播放器实现 粗糙的页面设计: wxml部分: <view class="test"><view class="img">& ...

  7. 利用Broadcast及相关组件实现简易音乐播放器功能

    目录 前言 项目源码 准备工作 代码编写 页面布局 Service类的创建 主函数的编写 项目心得 前言 在Andriod Studio中使用Broadcast实现了简易音乐播放器的功能.可以进行播放 ...

  8. PyQt5实现简易音乐播放器

    PyQt5实现简易音乐播放器 环境 vscode python 3.10.0 PyQt5 5.15.4 功能目标 能够读取本地的音乐文件,并实现播放的开关.曲目的切换和音量的加减 具体实现 新建一个文 ...

  9. 【Java实战】Java实现简易音乐播放器

    作者博客地址:http://www.yooongchun.cn/ 摘要:本文使用java基础技术实现了一个可播放mid.wav格式音乐的简易音乐播放器,带UI //此程序实现mid.wav格式音频文件 ...

最新文章

  1. 浅析redis与zookeeper构建分布式锁的异同
  2. hdu 5294 Tricks Device
  3. 构建虚拟主机以及访问控制
  4. 宿主机访问虚拟机中xampp搭建的站点失败
  5. c语言程序开发中连接是,C语言中等待socket连接和对socket定位的方法
  6. java重入锁 自旋锁_java 自旋锁(可重入且无死锁)
  7. OC高效率52之提供“全能初始化”方法
  8. 索尼耳机的降噪功能怎么样?
  9. 揭秘淘宝用户增长全链路项目管理
  10. excel固定一行不滚动怎么取消
  11. Python 中的 any(Python/any)
  12. 我的世界服务器配置文件
  13. 阿里云服务器域名备案
  14. 小厂B端产品啥都干——B端表格设计入门指南(中)
  15. android10全面屏手势 操作图,全面屏手势浪潮来临?安卓Q测试版新发现,手势操作十分便捷...
  16. 新版postman,代理抓包,抓不到https
  17. qq音乐播放按钮设计测试方案和qq登陆测试
  18. [转载]从100PV到1亿级PV网站架构演变
  19. verilog除法器
  20. Vue.js 中使用defineAsyncComponent 延迟加载组件

热门文章

  1. python多线程多个cpu_为什么python的多线程不能利用多核CPU?
  2. python开题报告范文样本,毕业论文开题报告怎么写
  3. 如何计算根号之牛顿迭代法
  4. 移动周报:七大无需编程的DIY开发工具
  5. SpringBoot: 启动Banner在线生成工具
  6. python处理svg_用Python/PIL读取SVG文件
  7. C#操作MicroSoft Word的代码
  8. Date.getyear()、Date.getMonth()、Date.getDay() 已经作废,其他解决办法
  9. ubuntu pci wifi bcm4322 无法使用 解决方法
  10. 利用Log parse 分析Exchange 性能并产生相应报表!(1)-Agent Log!