www.pudn.com > Mediaplayer.rar > MediaplayerDlg.cpp
// MediaplayerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Mediaplayer.h"
#include "MediaplayerDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMediaplayerDlg dialog
CMediaplayerDlg::CMediaplayerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMediaplayerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMediaplayerDlg)
// 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);
}
void CMediaplayerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMediaplayerDlg)
DDX_Control(pDX, IDC_MEDIAPLAYER1, m_ActiveMovie);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMediaplayerDlg, CDialog)
//{{AFX_MSG_MAP(CMediaplayerDlg)
ON_BN_CLICKED(IDC_OPEN, OnOpen)
ON_BN_CLICKED(IDC_PLAY, OnPlay)
ON_BN_CLICKED(IDC_STOP, OnStop)
ON_BN_CLICKED(IDC_LOWER, OnLower)
ON_BN_CLICKED(IDC_UPPER, OnUpper)
ON_BN_CLICKED(IDC_STATIC1, OnStatic1)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMediaplayerDlg message handlers
BOOL CMediaplayerDlg::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
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CMediaplayerDlg::OnOpen()
{
// TODO: Add your control notification handler code here
CString defFilter("Mp3 File(*.mp3)|*.mp3|Wma File(*.wma)|*.wma|Wave File(*.wav)|*.wav|");
CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY,defFilter);
if(dlg.DoModal()==IDOK){
CString PathName=dlg.GetPathName();
PathName.MakeUpper();
m_ActiveMovie.SetFileName(PathName);
SetDlgItemText(IDC_STATIC_NAME,PathName);
SetTimer(1,20,NULL);//设置定时器
}
}
void CMediaplayerDlg::OnPlay()
{
// TODO: Add your control notification handler code here
//m_ActiveMovie.SetCurrentPosition(10);//指点播放位置
m_ActiveMovie.SetCurrentPosition(pos);//指点播放位置
m_ActiveMovie.Play();//播放文件
SetTimer(1,20,NULL);//设置定时器
}
void CMediaplayerDlg::OnStop()
{
// TODO: Add your control notification handler code here
pos=m_ActiveMovie.GetCurrentPosition();
KillTimer(1);//关闭
double a=0.001;
CString str;
str.Format(L"%lf",pos);
SetDlgItemText(IDC_STATIC_TIME,str);
m_ActiveMovie.Stop();//停止播放文件
RETAILMSG(1,(_T("-FMD_Init\r\n")));
DEBUGMSG(1,(_T("-FMD_Init\r\n")));
}
void CMediaplayerDlg::OnLower()
{
// TODO: Add your control notification handler code here
long Volume=m_ActiveMovie.GetVolume();
m_ActiveMovie.Pause();
m_ActiveMovie.SetVolume(Volume-100);
m_ActiveMovie.Play();
}
void CMediaplayerDlg::OnUpper()
{
// TODO: Add your control notification handler code here
long Volume=m_ActiveMovie.GetVolume();
m_ActiveMovie.Pause();
m_ActiveMovie.SetVolume(Volume+100);
m_ActiveMovie.Play();
}
void CMediaplayerDlg::OnStatic1()
{
SHELLEXECUTEINFO shInfo;
memset(&shInfo, 0, sizeof(SHELLEXECUTEINFO));
shInfo.cbSize = sizeof(SHELLEXECUTEINFO);
shInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
// shInfo.lpFile = _T("http://www.baidu.com");
shInfo.lpFile = _T("Mediaplayer.exe");
shInfo.lpParameters = _T("-e\"work\"-m");
shInfo.lpDirectory = _T("\\windows");
ShellExecuteEx(&shInfo);
WaitForSingleObject(shInfo.hProcess,INFINITE);
AfxMessageBox(shInfo.lpFile);
}
void CMediaplayerDlg::OnTimer(UINT nIDEvent)
{
pos=m_ActiveMovie.GetCurrentPosition();
CString str,dura;
str.Format(L"%lf",pos); //注意其中的 "L"
// dura.Format(L"%lf",m_ActiveMovie.GetDuration());
//str=str+dura;
SetDlgItemText(IDC_STATIC_TIME,str);
//SetDlgItemText(IDC_STATIC_TIME,dura);
}