




已阅读5页,还剩10页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1. 新建一个基于对话框的player工程,对话框如图:2. 各个控件属性如下图:3. 在头文件playerDlg.h中添加如下:#if !defined(AFX_PLAYERDLG_H_A2A8C582_CC8E_4EED_85A6_7AC126703D36_INCLUDED_)#define AFX_PLAYERDLG_H_A2A8C582_CC8E_4EED_85A6_7AC126703D36_INCLUDED_#if _MSC_VER 1000#pragma once#endif / _MSC_VER 1000/ CPlayerDlg dialogclass CPlayerDlg : public CDialog/ Constructionpublic:CPlayerDlg(CWnd* pParent = NULL);/ standard constructorCString m_title;/歌曲名称UINT m_count;/标志DWORD cdlen; /歌曲时间CString FileName;BOOL m_flag;int i;int second,hour,minute;int m_max;CString stime;/播放时长CString allTime;/歌曲总时长DWORD cdfrom,cdto,aa;/歌曲的起点和终点/ Dialog Data/AFX_DATA(CPlayerDlg)enum IDD = IDD_PLAYER_DIALOG ;CStaticm_playing;CStaticm_ST_Pause;CSliderCtrlm_setvoice;CSliderCtrlm_control;CButtonm_delete;CButtonm_per;CButtonm_next;CButtonm_play;CButtonm_pause;CListBoxm_list2;/AFX_DATA/ ClassWizard generated virtual function overrides/AFX_VIRTUAL(CPlayerDlg)protected:virtual void DoDataExchange(CDataExchange* pDX);/ DDX/DDV support/AFX_VIRTUAL/ Implementationprotected:HICON m_hIcon;/ Generated message map functions/AFX_MSG(CPlayerDlg)virtual BOOL OnInitDialog();afx_msg void OnSysCommand(UINT nID, LPARAM lParam);afx_msg void OnPaint();afx_msg HCURSOR OnQueryDragIcon();afx_msg void AddSong();afx_msg void stopPlay();afx_msg void playSong(CString str);afx_msg void OnButtonPause();afx_msg void DelSong();afx_msg void OnSelchangelist();afx_msg void songListDBClk();afx_msg void NextSong();afx_msg DWORD setvolume(DWORD vol);afx_msg void preSong();afx_msg void OnTimer(UINT nIDEvent) ;afx_msg void OnButton1();afx_msg void deltSong();afx_msg DWORD getinfo(DWORD item);afx_msg void OnVoice(NMHDR* pNMHDR, LRESULT* pResult);afx_msg void Onsetvoices(NMHDR* pNMHDR, LRESULT* pResult);afx_msg void OnPrevis();afx_msg void OnNexts();afx_msg void Onexit();/AFX_MSGDECLARE_MESSAGE_MAP();4. 在playerDlg.cpp中的函数如下/ playerDlg.cpp : implementation file/#include stdafx.h#include player.h#include playerDlg.h#pragma comment(lib,winmm.lib)#include mmsystem.h#include Digitalv.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CAboutDlg dialog used for App AboutCString *songName= new CString 100;class CAboutDlg : public CDialogpublic: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/ Implementationprotected:/AFX_MSG(CAboutDlg)/AFX_MSGDECLARE_MESSAGE_MAP();CAboutDlg:CAboutDlg() : 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()/ CPlayerDlg dialogCPlayerDlg:CPlayerDlg(CWnd* pParent /*=NULL*/): CDialog(CPlayerDlg:IDD, pParent)m_hIcon = AfxGetApp()-LoadIcon(IDR_MAINFRAME);void CPlayerDlg:DoDataExchange(CDataExchange* pDX)CDialog:DoDataExchange(pDX);/AFX_DATA_MAP(CPlayerDlg)DDX_Control(pDX, IDC_PLAYING, m_playing);DDX_Control(pDX, IDC_ST_Pause, m_ST_Pause);DDX_Control(pDX, IDC_voice, m_setvoice);DDX_Control(pDX, IDC_BUTTON_DEL_SONG, m_delete);DDX_Control(pDX, IDC_BUTTON_PRE, m_per);DDX_Control(pDX, IDC_BUTTON_NEXT, m_next);DDX_Control(pDX, IDC_BUTTON_PAUSE, m_play);DDX_Control(pDX, m_list, m_list2);/AFX_DATA_MAPBEGIN_MESSAGE_MAP(CPlayerDlg, CDialog)/AFX_MSG_MAP(CPlayerDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BUTTON_ADD_SONG, AddSong)ON_BN_CLICKED(IDC_BUTTON_PAUSE, OnButtonPause)ON_BN_CLICKED(IDC_BUTTON_DEL_SONG, DelSong)ON_LBN_DBLCLK(m_list, songListDBClk)ON_BN_CLICKED(IDC_BUTTON_NEXT, NextSong)ON_BN_CLICKED(IDC_BUTTON_PRE, preSong)ON_WM_TIMER()ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_voice, Onsetvoices)ON_BN_CLICKED(IDC_BUTTON_PREVIS, OnPrevis)ON_BN_CLICKED(IDC_BUTTON_NEXTS, OnNexts)ON_BN_CLICKED(IDC_exit, Onexit)/AFX_MSG_MAPEND_MESSAGE_MAP()/ CPlayerDlg message handlersBOOL CPlayerDlg:OnInitDialog()CDialog:OnInitDialog();/ Add About. menu item to system menu.m_max=0;/进度条的最大位置初始值为0/ IDM_ABOUTBOX must be in the system command range.ASSERT(IDM_ABOUTBOX & 0xFFF0) = IDM_ABOUTBOX);ASSERT(IDM_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 icon/ TODO: Add extra initialization herem_setvoice.SetRange(0,1000);m_setvoice.SetPos(300);m_setvoice.SetTicFreq(1);/用于设置滑动条刻度的频度。默认为一个单位一个函数i = 0;m_max=0;second=0;minute=0;hour=0;return TRUE; / return TRUE unless you set the focus to a controlvoid CPlayerDlg: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 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 CPlayerDlg: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);elseCDialog:OnPaint();/ The system calls this to obtain the cursor to display while the user drags/ the minimized window.HCURSOR CPlayerDlg:OnQueryDragIcon()return (HCURSOR) m_hIcon;/添加歌曲afx_msg void CPlayerDlg:AddSong()char filefiler=mp3文件(*.mp3)|*.mp3| wma文件(*.wma)|*.wma| wav文件(*.wav)|*.wav|;CFileDialog f(true,NULL,NULL,OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT|OFN_ENABLESIZING,filefiler);f.m_ofn.Flags |=512;/可以选取多个曲目/选取内容部份if(f.DoModal()=IDOK)int index = m_list2.GetCurSel();FileName=f.GetPathName();/获取歌曲路径m_title=f.GetFileTitle(); /获取歌曲名称UpdateData(false);m_list2.AddString(FileName); /添加歌曲路径songNamem_list2.GetCount()-1 = f.GetFileTitle();/*MCIERROR mciSendCommand(MCIDEVICEID wIDDevice, /设备的ID,在打开设备时不用该参数UINTuMsg, /命令消息DWORD fdwCommand, /命令消息的标志DWORD dwParam /指向包含命令消息参数的结构); /若成功则返回0,否则返回错误码*/播放、暂停void CPlayerDlg:OnButtonPause() +i;if (i%2 = 1)KillTimer(0);MCI_PLAY_PARMS PlayParms;mciSendCommand (m_count, MCI_PAUSE, 0, (DWORD)(LPVOID) &PlayParms);SetDlgItemText(IDC_ST_Pause,播放);else if (i%2 = 0)SetTimer(0,1000,NULL);MCI_PLAY_PARMS PlayParms;mciSendCommand (m_count, MCI_RESUME, 0, (DWORD)(LPVOID) &PlayParms);SetDlgItemText(IDC_ST_Pause,暂停);/删除歌曲void CPlayerDlg:DelSong() CString str;int index = m_list2.GetCurSel(); m_list2.GetText(index,str); stopPlay(); m_list2.DeleteString(index);deltSong();/删除void CPlayerDlg:deltSong()int index = m_list2.GetCurSel();if (m_list2.GetCount()0)if (index = m_list2.GetCount()-1)index = -1;m_list2.GetText(index+1,FileName);m_list2.SetCurSel(index+1);playSong(FileName);else MessageBox(没有歌曲了啊);/双击播放void CPlayerDlg:songListDBClk() CFileDialog f(true);FileName=f.GetPathName();int i=m_list2.GetCurSel();m_list2.GetText(i,FileName);SetDlgItemText(IDC_PLAYING,songNamei);SetDlgItemText(IDC_ST_Pause,暂停);playSong(FileName);/停止播放void CPlayerDlg:stopPlay()mciSendCommand(m_count,MCI_CLOSE,0,NULL);m_count=0;m_flag=true;m_play.RedrawWindow();/播放音乐void CPlayerDlg:playSong(CString str)FileName=str;hour=0;minute=0;second=0;MCI_OPEN_PARMS mciopenparms;/打开MCI_PLAY_PARMS mciplayparms;/播放stopPlay();mciopenparms.lpstrElementName=FileName;/播放路径mciopenparms.lpstrDeviceType=NULL;/文件类型mciSendCommand(0,MCI_OPEN,MCI_DEVTYPE_WAVEFORM_AUDIO,(DWORD)(LPVOID)&mciopenparms);/向MCI设备发送命令消息m_count=mciopenparms.wDeviceID;mciplayparms.dwCallback=(DWORD)GetSafeHwnd();cdlen=getinfo(MCI_STATUS_LENGTH); /得到曲目长度 int sec = cdlen/1000;int min = sec/60;int sec2 =sec%60;allTime.Format(%02d:%02d:%02d,0,min,sec2);cdto=MCI_MAKE_HMS(MCI_HMS_HOUR(cdlen),MCI_HMS_MINUTE(cdlen),MCI_HMS_SECOND(cdlen); mciplayparms.dwFrom=0;mciplayparms.dwTo=cdto;mciSendCommand(m_count,MCI_PLAY,MCI_FROM,(DWORD)(LPVOID)& mciplayparms);SetTimer(0,1000,NULL);CClientDC dc(this);dc.SetBkColor(RGB(81,54,166);dc.SetTextColor(RGB(215,249,9);dc.TextOut(420,165,allTime);/下一曲void CPlayerDlg:NextSong() +i;int index = m_list2.GetCurSel();if (index =( m_list2.GetCount()-1)index = -1;m_list2.GetText(index + 1,FileName);m_list2.SetCurSel(index + 1);SetDlgItemText(IDC_PLAYING,songNameindex + 1);SetDlgItemText(IDC_ST_Pause,暂停);playSong(FileName);/上一曲void CPlayerDlg:preSong() +i;int index = m_list2.GetCurSel();if (index = 0)index = m_list2.GetCount();m_list2.GetText(index - 1,FileName);m_list2.SetCurSel(index - 1);SetDlgItemText(IDC_PLAYING,songNameindex - 1);SetDlgItemText(IDC_ST_Pause,暂停);playSong(FileName);/设置声音DWORD CPlayerDlg:setvolume(DWORD vol)MCI_DGV_SETAUDIO_PARMS setvolume;/这是设置音量的参数数据结构setvolume.dwCallback=NULL;setvolume.dwItem=MCI_DGV_SETAUDIO_VOLUME;/动作是设置音量setvolume.dwValue=vol;/音量值是volmciSendCommand(m_count,MCI_SETAUDIO,MCI_DGV_SETAUDIO_ITEM|MCI_DGV_SETAUDIO_VALUE,(DWORD)(LPVOID)&setvolume);return 0;/调节声音void CPlayerDlg:Onsetvoices(NMHDR* pNMHDR, LRESULT* pResult) / TODO: Add your control notification handler code heresetvolume(m_setvoice.GetPos();*pResult = 0;void CPlayerDlg:OnTimer(UINT nIDEvent) /CString stime; second+;CClientDC dc(this); dc.SetBkColor(RGB(81,54,166);/设置放置计数器区域的外观 dc.SetTextColor(RGB(215,249,9);/设置数字显示的颜色 if(second=60)/设置钟表的显示 minute+; second=0; if(minute=60) hour+; minute=0; if(hour=24) hour=0; stime.Format(%02d:%02d:%02d,hour,minute,second);/显示时间进度 dc.TextOut(115,165,stime);/播放完后自动播放下一曲if (sti
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 火化安葬协议书
- 民事结案协议书
- 残联安置协议书
- 车辆交割协议书模板
- 实习协议与保密协议
- 国有企业借款合同
- 公司股份制合同协议书
- 环境工程污水处理技术应用试题集
- 商务往来文书与合同样本集
- 比赛授权协议书
- 2025年日历表(A4版含农历可编辑)
- T-GDWCA 0033-2018 耳机线材标准规范
- NB/T 10533-2021采煤沉陷区治理技术规范
- GA/T 1068-2015刑事案件命名规则
- 主治医师聘用合同
- 2021年四川绵竹高发投资有限公司招聘笔试试题及答案解析
- 建设工程消防验收备案抽查复查申请表
- 水费计算、水权与水价课件
- 思想道德与法治课件:第六章 第一节 社会主义法律的特征和运行
- 61850报文解析-深瑞版-131016
- 江西新定额2017土建定额说明及解释
评论
0/150
提交评论