基于MFC的音乐播放器vc6.docx

上传人:b****3 文档编号:6763472 上传时间:2023-05-10 格式:DOCX 页数:20 大小:71.60KB
下载 相关 举报
基于MFC的音乐播放器vc6.docx_第1页
第1页 / 共20页
基于MFC的音乐播放器vc6.docx_第2页
第2页 / 共20页
基于MFC的音乐播放器vc6.docx_第3页
第3页 / 共20页
基于MFC的音乐播放器vc6.docx_第4页
第4页 / 共20页
基于MFC的音乐播放器vc6.docx_第5页
第5页 / 共20页
基于MFC的音乐播放器vc6.docx_第6页
第6页 / 共20页
基于MFC的音乐播放器vc6.docx_第7页
第7页 / 共20页
基于MFC的音乐播放器vc6.docx_第8页
第8页 / 共20页
基于MFC的音乐播放器vc6.docx_第9页
第9页 / 共20页
基于MFC的音乐播放器vc6.docx_第10页
第10页 / 共20页
基于MFC的音乐播放器vc6.docx_第11页
第11页 / 共20页
基于MFC的音乐播放器vc6.docx_第12页
第12页 / 共20页
基于MFC的音乐播放器vc6.docx_第13页
第13页 / 共20页
基于MFC的音乐播放器vc6.docx_第14页
第14页 / 共20页
基于MFC的音乐播放器vc6.docx_第15页
第15页 / 共20页
基于MFC的音乐播放器vc6.docx_第16页
第16页 / 共20页
基于MFC的音乐播放器vc6.docx_第17页
第17页 / 共20页
基于MFC的音乐播放器vc6.docx_第18页
第18页 / 共20页
基于MFC的音乐播放器vc6.docx_第19页
第19页 / 共20页
基于MFC的音乐播放器vc6.docx_第20页
第20页 / 共20页
亲,该文档总共20页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

基于MFC的音乐播放器vc6.docx

《基于MFC的音乐播放器vc6.docx》由会员分享,可在线阅读,更多相关《基于MFC的音乐播放器vc6.docx(20页珍藏版)》请在冰点文库上搜索。

基于MFC的音乐播放器vc6.docx

基于MFC的音乐播放器vc6

1.新建一个基于对话框的player工程,对话框如图:

2.各个控件属性如下图:

3.在头文件playerDlg.h中添加如下:

#if!

defined(AFX_PLAYERDLG_H__A2A8C582_CC8E_4EED_85A6_7AC126703D36__INCLUDED_)

#defineAFX_PLAYERDLG_H__A2A8C582_CC8E_4EED_85A6_7AC126703D36__INCLUDED_

#if_MSC_VER>1000

#pragmaonce

#endif//_MSC_VER>1000

/////////////////////////////////////////////////////////////////////////////

//CPlayerDlgdialog

classCPlayerDlg:

publicCDialog

{

//Construction

public:

CPlayerDlg(CWnd*pParent=NULL);//standardconstructor

CStringm_title;//歌曲名称

UINTm_count;//标志

DWORDcdlen;//歌曲时间

CStringFileName;

BOOLm_flag;

inti;

intsecond,hour,minute;

intm_max;

CStringstime;//播放时长

CStringallTime;//歌曲总时长

DWORDcdfrom,cdto,aa;//歌曲的起点和终点

//DialogData

//{{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

//ClassWizardgeneratedvirtualfunctionoverrides

//{{AFX_VIRTUAL(CPlayerDlg)

protected:

virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport

//}}AFX_VIRTUAL

//Implementation

protected:

HICONm_hIcon;

//Generatedmessagemapfunctions

//{{AFX_MSG(CPlayerDlg)

virtualBOOLOnInitDialog();

afx_msgvoidOnSysCommand(UINTnID,LPARAMlParam);

afx_msgvoidOnPaint();

afx_msgHCURSOROnQueryDragIcon();

afx_msgvoidAddSong();

afx_msgvoidstopPlay();

afx_msgvoidplaySong(CStringstr);

afx_msgvoidOnButtonPause();

afx_msgvoidDelSong();

afx_msgvoidOnSelchangelist();

afx_msgvoidsongListDBClk();

afx_msgvoidNextSong();

afx_msgDWORDsetvolume(DWORDvol);

afx_msgvoidpreSong();

afx_msgvoidOnTimer(UINTnIDEvent);

afx_msgvoidOnButton1();

afx_msgvoiddeltSong();

afx_msgDWORDgetinfo(DWORDitem);

afx_msgvoidOnVoice(NMHDR*pNMHDR,LRESULT*pResult);

afx_msgvoidOnsetvoices(NMHDR*pNMHDR,LRESULT*pResult);

afx_msgvoidOnPrevis();

afx_msgvoidOnNexts();

afx_msgvoidOnexit();

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

4.在playerDlg.cpp中的函数如下

//playerDlg.cpp:

implementationfile

//

#include"stdafx.h"

#include"player.h"

#include"playerDlg.h"

#pragmacomment(lib,"winmm.lib")

#include"mmsystem.h"

#include"Digitalv.h"

#ifdef_DEBUG

#definenewDEBUG_NEW

#undefTHIS_FILE

staticcharTHIS_FILE[]=__FILE__;

#endif

//CAboutDlgdialogusedforAppAbout

CString*songName=newCString[100];

classCAboutDlg:

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

//Implementation

protected:

//{{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_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

//CPlayerDlgdialog

CPlayerDlg:

:

CPlayerDlg(CWnd*pParent/*=NULL*/)

:

CDialog(CPlayerDlg:

:

IDD,pParent)

{

m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}

voidCPlayerDlg:

:

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_MAP

}

BEGIN_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_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

//CPlayerDlgmessagehandlers

BOOLCPlayerDlg:

:

OnInitDialog()

{

CDialog:

:

OnInitDialog();

//Add"About..."menuitemtosystemmenu.

m_max=0;//进度条的最大位置初始值为0

//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

//TODO:

Addextrainitializationhere

m_setvoice.SetRange(0,1000);

m_setvoice.SetPos(300);

m_setvoice.SetTicFreq

(1);//用于设置滑动条刻度的频度。

默认为一个单位一个函数

i=0;

m_max=0;

second=0;

minute=0;

hour=0;

returnTRUE;//returnTRUEunlessyousetthefocustoacontrol

}

voidCPlayerDlg:

:

OnSysCommand(UINTnID,LPARAMlParam)

{

if((nID&0xFFF0)==IDM_ABOUTBOX)

{

CAboutDlgdlgAbout;

dlgAbout.DoModal();

}

else

{

CDialog:

:

OnSysCommand(nID,lParam);

}

}

//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow

//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,

//thisisautomaticallydoneforyoubytheframework.

voidCPlayerDlg:

:

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();

}

}

//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags

//theminimizedwindow.

HCURSORCPlayerDlg:

:

OnQueryDragIcon()

{

return(HCURSOR)m_hIcon;

}

//添加歌曲

afx_msgvoidCPlayerDlg:

:

AddSong()

{

charfilefiler[]="mp3文件(*.mp3)|*.mp3|"

"wma文件(*.wma)|*.wma|"

"wav文件(*.wav)|*.wav|";

CFileDialogf(true,NULL,NULL,OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT|OFN_ENABLESIZING,filefiler);

f.m_ofn.Flags|=512;//可以选取多个曲目

//选取内容部份

if(f.DoModal()==IDOK)

{

intindex=m_list2.GetCurSel();

FileName=f.GetPathName();//获取歌曲路径

m_title=f.GetFileTitle();//获取歌曲名称

UpdateData(false);

}

m_list2.AddString(FileName);//添加歌曲路径

songName[m_list2.GetCount()-1]=f.GetFileTitle();

}

/*

MCIERRORmciSendCommand

MCIDEVICEIDwIDDevice, //设备的ID,在打开设备时不用该参数

UINT    uMsg,   //命令消息

DWORD   fdwCommand,//命令消息的标志

DWORD   dwParam  //指向包含命令消息参数的结构

);//若成功则返回0,否则返回错误码

*/

//播放、暂停

voidCPlayerDlg:

:

OnButtonPause()

{

++i;

if(i%2==1)

{

KillTimer(0);

MCI_PLAY_PARMSPlayParms;

mciSendCommand(m_count,MCI_PAUSE,0,(DWORD)(LPVOID)&PlayParms);

SetDlgItemText(IDC_ST_Pause,"播放");

}

elseif(i%2==0)

{

SetTimer(0,1000,NULL);

MCI_PLAY_PARMSPlayParms;

mciSendCommand(m_count,MCI_RESUME,0,(DWORD)(LPVOID)&PlayParms);

SetDlgItemText(IDC_ST_Pause,"暂停");

}

}

//删除歌曲

voidCPlayerDlg:

:

DelSong()

{

CStringstr;

intindex=m_list2.GetCurSel();

m_list2.GetText(index,str);

stopPlay();

m_list2.DeleteString(index);

deltSong();

}

//删除

voidCPlayerDlg:

:

deltSong()

{

intindex=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("没有歌曲了啊");

}

//双击播放

voidCPlayerDlg:

:

songListDBClk()

{

CFileDialogf(true);

FileName=f.GetPathName();

inti=m_list2.GetCurSel();

m_list2.GetText(i,FileName);

SetDlgItemText(IDC_PLAYING,songName[i]);

SetDlgItemText(IDC_ST_Pause,"暂停");

playSong(FileName);

}

//停止播放

voidCPlayerDlg:

:

stopPlay()

{

mciSendCommand(m_count,MCI_CLOSE,0,NULL);

m_count=0;

m_flag=true;

m_play.RedrawWindow();

}

//播放音乐

voidCPlayerDlg:

:

playSong(CStringstr)

{

FileName=str;

hour=0;

minute=0;

second=0;

MCI_OPEN_PARMSmciopenparms;//打开

MCI_PLAY_PARMSmciplayparms;//播放

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);//得到曲目长度

intsec=cdlen/1000;

intmin=sec/60;

intsec2=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)&

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2