www.pudn.com > mp3.rar > Mp3PlayerDlg.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 
 
	CBitmap bmp; 
	bmp.LoadBitmap(IDB_BITMAP1); 
     
	m_Audio = NULL; 
	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()  
{ 
 
	 
	if(m_Audio == NULL) 
	{ 
		m_Audio = MCIWndCreate(this->GetSafeHwnd(), 
			AfxGetInstanceHandle(), 
			WS_CHILD | WS_VISIBLE/*|MCIWNDF_NOMENU*/,m_Path); 
		m_Status.SetWindowText(_T("Playing...")); 
	 
	} 
	else 
	{ 
		MCIWndDestroy(m_Audio); 
		m_Audio = MCIWndCreate(this->GetSafeHwnd(), 
			AfxGetInstanceHandle(), 
			WS_CHILD | WS_VISIBLE/*|MCIWNDF_NOMENU*/,m_Path); 
		m_Status.SetWindowText(_T("Playing...")); 
	} 
	MCIWndPlay(m_Audio); 
	Pause = FALSE; 
	m_Play.EnableWindow(TRUE);	 
} 
 
 
void CMp3PlayerDlg::OnOpen()  
{ 
		static char szFilter[]="MP3 Files (*.mp3)|*.mp3|WAV Files (*.wav)|*.wav|AVI Files (*.avi)|*.avi|"; 
        CFileDialog mp3(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilter); 
		if(mp3.DoModal() == IDOK) 
		{ 
			m_Path = mp3.GetPathName(); 
			OnPlay(); 
			UpdateData(FALSE); 
		} 
	/*	char szFileFilter[]="AVI File(*.avi)|*.avi|" 
		                "MP3 File(*.mp3)|*.mp3|" 
						"All File(*.*)|*.*||"; 
	CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFileFilter); 
	if(dlg.DoModal()==IDOK) 
	{ 
		CString PathName=dlg.GetPathName(); 
		PathName.MakeUpper(); 
	    m_wm.SetUrl(PathName); 
	}*/ 
}