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

📄 richimp3dlg.cpp

📁 完整的MP3播放器源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// RichiMP3Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "RichiMP3.h"
#include "RichiMP3Dlg.h"
#include "DlgProxy.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
// user thresd notification
#define WM_FILE_PLAYED (WM_USER+1000)



//callback fot each sample added to the sound out buffer
DWORD CRichiMP3Dlg::DecCallback(double *pVal, double *pSpectrum,int nChannel);
// play thread
int CRichiMP3Dlg::PlayThread(void* pData);
CWndGraph*          CRichiMP3Dlg::m_scope = 0;
CBytesTracer* CRichiMP3Dlg::m_ctrl1 = 0;
CBytesTracer* CRichiMP3Dlg::m_ctrl2 = 0;
double             CRichiMP3Dlg::m_preVol=20.0;

class 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_MSG
	DECLARE_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()

/////////////////////////////////////////////////////////////////////////////
// CRichiMP3Dlg dialog

IMPLEMENT_DYNAMIC(CRichiMP3Dlg, CDialog);

CRichiMP3Dlg::CRichiMP3Dlg(CWnd* pParent /*=NULL*/)
	: CBitmapDialog(CRichiMP3Dlg::IDD, pParent),m_break(FALSE),
    m_fppos(0),m_hThread(0),m_buffsize(4 * 8912),m_ignoreMsg(FALSE),
    m_playIdx(-1),m_pDecoder(0),m_pspf(0),m_about(0)
{
	//{{AFX_DATA_INIT(CRichiMP3Dlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_pAutoProxy = NULL;
	bLoop = FALSE;
	bStop = FALSE;
	bPause = FALSE;
	nCurPos = 0;
	pListDlg = new CFileListDlg(this);
	pEqDlg = new CEqDlg(this);
}

CRichiMP3Dlg::~CRichiMP3Dlg()
{
	// If there is an automation proxy for this dialog, set
	//  its back pointer to this dialog to NULL, so it knows
	//  the dialog has been deleted.
	if (m_pAutoProxy != NULL)
		m_pAutoProxy->m_pDialog = NULL;
	if(pListDlg != NULL)
		delete pListDlg;
	if(pEqDlg != NULL)
		delete pEqDlg;
}

void CRichiMP3Dlg::DoDataExchange(CDataExchange* pDX)
{
	CBitmapDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRichiMP3Dlg)
	DDX_Control(pDX, IDC_SLIDER3, m_pre);
	DDX_Control(pDX, IDC_SLIDER2, m_fp);
	DDX_Control(pDX, EF_B2, ef_b2);
	DDX_Control(pDX, EF_B3, ef_b3);
	DDX_Control(pDX, IDC_LIST2, m_list);
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CRichiMP3Dlg, CBitmapDialog)
	//{{AFX_MSG_MAP(CRichiMP3Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_BUTTON_BACK, OnButtonBack)
	ON_BN_CLICKED(IDC_BUTTON_END, OnButtonEnd)
	ON_BN_CLICKED(IDC_BUTTON_FIRST, OnButtonFirst)
	ON_BN_CLICKED(IDC_BUTTON_FORWARD, OnButtonForward)
	ON_BN_CLICKED(IDC_BUTTON_LIST, OnButtonList)
	ON_BN_CLICKED(IDC_BUTTON_LOOP, OnButtonLoop)
	ON_BN_CLICKED(IDC_BUTTON_PAUSE, OnButtonPause)
	ON_BN_CLICKED(IDC_BUTTON_PLAY, OnButtonPlay)
	ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_BN_CLICKED(IDC_BUTTON_CLOSE, OnButtonClose)
	ON_BN_CLICKED(IDC_BUTTON_ABOUT, OnButtonAbout)
	ON_BN_CLICKED(IDC_BUTTON_MIN, OnButtonMin)
	ON_BN_CLICKED(IDC_BUTTON_HELP, OnButtonHelp)
	ON_LBN_DBLCLK(IDC_LIST2, OnFileChange)
	ON_WM_HSCROLL()
	ON_WM_DESTROY()
	ON_LBN_SELCHANGE(IDC_LIST2, OnSelchangeList2)
	ON_WM_VSCROLL()
	ON_BN_CLICKED(IDC_BUTTON_LIST2, OnButtonList2)
	ON_MESSAGE(WM_VSCROLL1,OnVScroll1)
	ON_BN_CLICKED(IDC_BUTTON_TITLE, OnButtonTitle)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_FILE_PLAYED,OnFilePlayed)
	ON_MESSAGE(WM_SETCHANGED, OnIdUpdate)
	ON_MESSAGE(WM_FILECHANGED, OnFileChanged)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRichiMP3Dlg message handlers

BOOL CRichiMP3Dlg::OnInitDialog()
{
	CBitmapDialog::OnInitDialog();

	SetBitmap(IDB_BITMAP_BACK1);
	// Add "About..." menu item to system menu.
	VERIFY(btnFirst.SubclassDlgItem(IDC_BUTTON_FIRST, this));
	VERIFY(btnFirst.LoadBitmaps(_T("firstu"), _T("firstd"), _T("firstf"),_T("firstx")));

	VERIFY(btnForward.SubclassDlgItem(IDC_BUTTON_FORWARD, this));
	VERIFY(btnForward.LoadBitmaps(_T("forwardu"), _T("forwardd"), _T("forwardf"),_T("forwardx")));

	VERIFY(btnPlay.SubclassDlgItem(IDC_BUTTON_PLAY, this));
	VERIFY(btnPlay.LoadBitmaps(_T("hplayu"),_T("hplayd"), _T("hplayf"),_T("hplayx")));

	VERIFY(btnPause.SubclassDlgItem(IDC_BUTTON_PAUSE, this));
	VERIFY(btnPause.LoadBitmaps(_T("pauseu"), _T("paused"), _T("pausef"),_T("pausex")));

	VERIFY(btnStop.SubclassDlgItem(IDC_BUTTON_STOP, this));
	VERIFY(btnStop.LoadBitmaps(_T("hstopu"), _T("hstopd"), _T("hstopf"),_T("hstopx")));
	///////////////////////////
	VERIFY(btnBack.SubclassDlgItem(IDC_BUTTON_BACK, this));
	VERIFY(btnBack.LoadBitmaps(_T("backu"), _T("backd"), _T("backf"),_T("backx")));

	VERIFY(btnEnd.SubclassDlgItem(IDC_BUTTON_END, this));
	VERIFY(btnEnd.LoadBitmaps(_T("endu"), _T("endd"), _T("endf"),_T("endx")));

	VERIFY(btnLoop.SubclassDlgItem(IDC_BUTTON_LOOP, this));
	VERIFY(btnLoop.LoadBitmaps(_T("loopu"),_T("loopd"), _T("loopf"),_T("loopx")));

	VERIFY(btnList.SubclassDlgItem(IDC_BUTTON_LIST, this));
	VERIFY(btnList.LoadBitmaps(_T("listu"), _T("listd"), _T("listf"),_T("listx")));

	VERIFY(btnEq.SubclassDlgItem(IDC_BUTTON_LIST2, this));
	VERIFY(btnEq.LoadBitmaps(_T("listu"), _T("listd"), _T("listf"),_T("listx")));



	VERIFY(btnHelp.SubclassDlgItem(IDC_BUTTON_HELP, this));
	VERIFY(btnHelp.LoadBitmaps(_T("helpu"), _T("helpd"), _T("helpf")));


	VERIFY(btnAbout.SubclassDlgItem(IDC_BUTTON_ABOUT, this));
	VERIFY(btnAbout.LoadBitmaps(_T("aboutu"), _T("aboutd"), _T("aboutf")));


	VERIFY(btnMin.SubclassDlgItem(IDC_BUTTON_MIN, this));
	VERIFY(btnMin.LoadBitmaps(_T("minu"), _T("mind"), _T("minf")));


	VERIFY(btnClose.SubclassDlgItem(IDC_BUTTON_CLOSE, this));
	VERIFY(btnClose.LoadBitmaps(_T("closeu"), _T("closed"), _T("closef")));

	VERIFY(btnTitle.SubclassDlgItem(IDC_BUTTON_TITLE, this));
	VERIFY(btnTitle.LoadBitmaps(_T("titleu"), _T("titled"), _T("titlef")));

	SetWindowText("RichiMP3播放器");
	InitializeCriticalSection(&m_css);
    CBytesTracer::CreateTracer();
		m_highProcSpeed = TRUE;
		m_play  = FALSE;
    m_expand = FALSE;
    
	// 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 dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	m_preVol = 10;
	m_pre.SetRange(1,15);
    m_pre.SetPos(m_preVol);
	m_buffsize = 2 * 16384;

	m_ctrl1 = new CBytesTracer;
	m_ctrl2 = new CBytesTracer;
	m_ctrl1->CreatWndw(IDC_S1,this);
		m_ctrl1->m_startColor = RGB(0,0,255);
		m_ctrl1->m_endColor = RGB(255,0,0);
		m_ctrl1->m_backColor = RGB(0,0,0);
		m_ctrl1->m_overColor = RGB(255,255,96);

		m_ctrl2->CreatWndw(IDC_S2,this);
		m_ctrl2->m_startColor = RGB(0,0,255);
		m_ctrl2->m_endColor = RGB(255,255,128);
		m_ctrl2->m_backColor = RGB(0,0,0);
		m_ctrl2->m_overColor = RGB(255,255,96);
		CWndGraph::RegisterGraphClass();
	m_scope = new CWndGraph;
	m_scope->CreateWndw(IDC_GRPH,this);
	CListBox *pListBox = (CListBox *)GetDlgItem(IDC_LIST2);
	pListBox->ResetContent();
	CPictureList *pList = (CPictureList *)GetApp()->GetPictureList();
	POSITION pos = pList->GetHeadPosition();
	while(pos != NULL)
	{
		CPictureObject *pObject = (CPictureObject *)pList->GetNext(pos);
		CString strFileName;
		CString strName;
		strFileName = pObject->GetFileName();
		int n = strFileName.ReverseFind('\\');
		int n1 = strFileName.GetLength();
		if(n>0)
		{
			strName = strFileName.Right(n1-n-1);
		}

		int nCurSel = pListBox->AddString(strName);
		pListBox->SetItemData(nCurSel,(DWORD)pObject);

	}
	if(pListBox->GetCount() >=1)
	{
		pListBox->SetCurSel(1);
	}
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CRichiMP3Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CBitmapDialog::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 CRichiMP3Dlg::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
	{
		CBitmapDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CRichiMP3Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

// Automation servers should not exit when a user closes the UI
//  if a controller still holds on to one of its objects.  These
//  message handlers make sure that if the proxy is still in use,
//  then the UI is hidden but the dialog remains around if it
//  is dismissed.

void CRichiMP3Dlg::OnClose() 
{
	if (CanExit())
		CBitmapDialog::OnClose();
}

void CRichiMP3Dlg::OnOK() 
{
	if (CanExit())
		CBitmapDialog::OnOK();
}

void CRichiMP3Dlg::OnCancel() 
{
	if (CanExit())
		CBitmapDialog::OnCancel();
}

BOOL CRichiMP3Dlg::CanExit()
{
	// If the proxy object is still around, then the automation
	//  controller is still holding on to this application.  Leave
	//  the dialog around, but hide its UI.
	if (m_pAutoProxy != NULL)
	{
		ShowWindow(SW_HIDE);
		return FALSE;
	}

	return TRUE;
}

BOOL CRichiMP3Dlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CBitmapDialog::PreTranslateMessage(pMsg);
}

void CRichiMP3Dlg::OnButtonBack() 
{
	// TODO: Add your control notification handler code here
	if(m_hThread == 0)
            return;
	int nMax;
	int nMin;
	int nPos;
	nMin = m_fp.GetRangeMin();
	nMax = m_fp.GetRangeMax();
	nPos = m_fp.GetPos();
	int nDelta = (nMax - nMin)/100;
	int nNewPos;
	nNewPos = nPos;
	if((nPos + nDelta)>nMax)
		nNewPos = nMax;
	else
		nNewPos +=nDelta;
	m_fp.SetPos(nNewPos);
	::EnterCriticalSection(&m_css);
			m_fppos  = m_fp.GetPos();
			int sec;
			sec = m_fppos*m_pspf/1000;
			if(sec != 0)
			{
					ef_b2.Display(sec/60);
					ef_b3.Display(sec%60);
			}
			else
			{
					ef_b2.Display(0);
					ef_b3.Display(00);
			}
			m_pFile.Goto((m_fppos * m_frmLength / 4) * 4);
			::LeaveCriticalSection(&m_css);
}

void CRichiMP3Dlg::OnButtonEnd() 
{
	// TODO: Add your control notification handler code here
	if(m_hThread == 0)
		return;
	if(m_hThread)
    {
        ::EnterCriticalSection(&m_css);
		m_fppos  = m_fp.GetRangeMax();
		int sec;
		sec = m_fppos*m_pspf/1000;
		ef_b2.Display(sec/60);
		ef_b3.Display(sec%60);
			m_pFile.Goto(m_pFile.GetLength());//(m_fppos * m_frmLength / 4) * 4);

⌨️ 快捷键说明

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