⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mp3playerdlg.cpp

📁 一个简单的MP3播放器2 一个简单的MP3播放器2
💻 CPP
字号:
// Mp3PlayerDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Mp3Player.h"
#include "Mp3PlayerDlg.h"
#include "vfw.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMp3PlayerDlg dialog

CMp3PlayerDlg::CMp3PlayerDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMp3PlayerDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMp3PlayerDlg)
	m_Path = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMp3PlayerDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMp3PlayerDlg)
	DDX_Control(pDX, IDC_Status2, m_Status);
	DDX_Control(pDX, ID_Play, m_Play);
	DDX_Control(pDX, ID_Pause, m_Pause);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMp3PlayerDlg, CDialog)
	//{{AFX_MSG_MAP(CMp3PlayerDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(ID_Exit, OnExit)
	ON_BN_CLICKED(ID_Stop, OnStop)
	ON_BN_CLICKED(ID_Pause, OnPause)
	ON_BN_CLICKED(ID_Play, OnPlay)
	ON_BN_CLICKED(ID_Open, OnOpen)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMp3PlayerDlg message handlers

BOOL CMp3PlayerDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// 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 CMp3PlayerDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int 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 icon
		dc.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 CMp3PlayerDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMp3PlayerDlg::OnExit() 
{

		if(m_Audio !=NULL)
	{
		MCIWndDestroy(m_Audio);
		OnOK();
	}
	{	
MessageBox(" Please take some time to report any bugs to zxn@public2.hk.hi.cn", "Please Send Some Feedback");	
}
	CDialog::OnCancel();
}

void CMp3PlayerDlg::OnStop() 
{
	MCIWndStop(m_Audio);
	if(m_Audio !=NULL)
	{
		MCIWndDestroy(m_Audio);
	m_Status.SetWindowText(_T("Selection Stoped"));
	}
	m_Play.EnableWindow(TRUE);
	
}

void CMp3PlayerDlg::OnPause() 
{
	if(Pause)
	{
		m_Pause.SetWindowText("Pause");
		MCIWndResume(m_Audio);
		Pause = FALSE;
	m_Status.SetWindowText(_T("Selection Paused"));
	}
	else
	{
		m_Pause.SetWindowText("Pause");
		MCIWndPause(m_Audio);
		Pause = TRUE;
	}
	
}

void CMp3PlayerDlg::OnPlay() 
{
	m_Audio = NULL;
	
	if(m_Audio == NULL)
	{
		m_Audio = MCIWndCreate(this->GetSafeHwnd(),
			AfxGetInstanceHandle(),
			WS_CHILD | WS_VISIBLE|MCIWNDF_NOMENU,m_Path);
		m_Status.SetWindowText(_T("Playing..."));
	}
	else
	{
		MCIWndHome(m_Audio);
	}
	
	MCIWndPlay(m_Audio);
	Pause = FALSE;
	m_Play.EnableWindow(TRUE);	
}


void CMp3PlayerDlg::OnOpen() 
{
	m_Audio = NULL;
	if(m_Audio == NULL)
	{
		CFileDialog mp3(TRUE,NULL,NULL,OFN_HIDEREADONLY,"MP3 Files (*.mp3)|*.mp3|");
		if(mp3.DoModal() == IDOK)
		{
			m_Path = mp3.GetPathName();
			UpdateData(FALSE);
		
		}
	}	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -