www.pudn.com > shipinbofang.rar > PlayMediaView.cpp


// PlayMediaView.cpp : implementation of the CPlayMediaView class 
// 
 
#include "stdafx.h" 
#include "PlayMedia.h" 
 
#include "PlayMediaDoc.h" 
#include "PlayMediaView.h" 
#include "wmpsettings.h" 
#include "wmpcontrols.h" 
 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CPlayMediaView 
 
IMPLEMENT_DYNCREATE(CPlayMediaView, CView) 
 
BEGIN_MESSAGE_MAP(CPlayMediaView, CView) 
	//{{AFX_MSG_MAP(CPlayMediaView) 
	ON_WM_CREATE() 
	ON_COMMAND(ID_OPER_OPENV, OnOperOpenv) 
	ON_COMMAND(ID_OPER_PLAYV, OnOperPlayv) 
	ON_COMMAND(ID_OPER_STOPV, OnOperStopv) 
	ON_COMMAND(ID_OPER_OPENA, OnOperOpena) 
	ON_COMMAND(ID_OPER_PLAYA, OnOperPlaya) 
	ON_COMMAND(ID_OPER_STOPA, OnOperStopa) 
	ON_WM_SIZE() 
	//}}AFX_MSG_MAP 
	// Standard printing commands 
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) 
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) 
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CPlayMediaView construction/destruction 
 
CPlayMediaView::CPlayMediaView() 
{ 
	// TODO: add construction code here 
 
	//添加代码 
	m_Video=new CWMPPlayer4; 
	m_Music=new CWMPPlayer4; 
} 
 
CPlayMediaView::~CPlayMediaView() 
{ 
	delete m_Video; 
	delete m_Music; 
} 
 
BOOL CPlayMediaView::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return CView::PreCreateWindow(cs); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CPlayMediaView drawing 
 
void CPlayMediaView::OnDraw(CDC* pDC) 
{ 
	CPlayMediaDoc* pDoc = GetDocument(); 
	ASSERT_VALID(pDoc); 
	// TODO: add draw code for native data here 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CPlayMediaView printing 
 
BOOL CPlayMediaView::OnPreparePrinting(CPrintInfo* pInfo) 
{ 
	// default preparation 
	return DoPreparePrinting(pInfo); 
} 
 
void CPlayMediaView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add extra initialization before printing 
} 
 
void CPlayMediaView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add cleanup after printing 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CPlayMediaView diagnostics 
 
#ifdef _DEBUG 
void CPlayMediaView::AssertValid() const 
{ 
	CView::AssertValid(); 
} 
 
void CPlayMediaView::Dump(CDumpContext& dc) const 
{ 
	CView::Dump(dc); 
} 
 
CPlayMediaDoc* CPlayMediaView::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPlayMediaDoc))); 
	return (CPlayMediaDoc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CPlayMediaView message handlers 
 
int CPlayMediaView::OnCreate(LPCREATESTRUCT lpCreateStruct)  
{ 
	if (CView::OnCreate(lpCreateStruct) == -1) 
		return -1; 
	 
	// TODO: Add your specialized creation code here 
	///添加的代码 
	HCURSOR hCursor=::LoadCursor(NULL,IDC_ARROW);//获得标准箭头的鼠标指针 
	m_Video->Create(AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS|CS_PARENTDC,hCursor,0,0),NULL,WS_VISIBLE|WS_CHILD,CRect(0,0,0,0),this,0); 
	//创建视频窗口 
    m_Video->SetUiMode("none"); 
	m_Video->GetSettings().SetMute(TRUE); 
	//由于使用单独的音频来播放将视频设置为静音模式 
	m_Music->Create(AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS|CS_PARENTDC,hCursor,0,0),NULL,WS_VISIBLE|WS_CHILD,CRect(0,0,0,0),this,0); 
	//创建音频窗口 
	m_Music->ShowWindow(SW_HIDE);//将音频设置为不可见 
	return 0; 
} 
 
void CPlayMediaView::OnOperOpenv()  
{ 
	// TODO: Add your command handler code here 
	//自己添加的代码 
	static char BASED_CODE szFilter[]="Video Files(*.avi;*.mpg;*.mpeg)|*.avi;*.mpg;*.mpeg|All File(*.*)|*.*"; 
	//只允许打开视频文件 
	CFileDialog fileDlg(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFilter); 
	if(fileDlg.DoModal()==IDOK) 
		m_strVideo=fileDlg.GetPathName();//获得视频文件名 
} 
 
void CPlayMediaView::OnOperPlayv()  
{ 
	// TODO: Add your command handler code here 
	m_Video->GetControls().stop();//首先停止正在播放的视频文件 
	m_Video->GetSettings().SetAutoStart(TRUE);//准备播放 
	m_Video->SetUrl(m_strVideo);//载入视频文件自动播放 
} 
 
void CPlayMediaView::OnOperStopv()  
{ 
	// TODO: Add your command handler code here 
	///添加代码开始 
	m_Video->GetControls().stop();//停止播放 
	 
} 
 
void CPlayMediaView::OnOperOpena()  
{ 
	// TODO: Add your command handler code here 
	//添加的开始 
	static char BASED_CODE szFilter[]="Audio Files(*.wav;*.mp3)|*.wav;*.mp3||"; 
	//只允许打开视频文件 
	CFileDialog fileDlg(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFilter); 
	if(fileDlg.DoModal()==IDOK) 
		m_strMusic=fileDlg.GetPathName();//获得音频文件名	 
} 
 
void CPlayMediaView::OnOperPlaya()  
{ 
	// TODO: Add your command handler code here 
	//添加的代码的开始 
	m_Music->GetControls().stop();//首先停止正在播放的音频文件 
	m_Music->GetSettings().SetAutoStart(TRUE);//准备播放 
	m_Music->SetUrl(m_strMusic);//载入视频文件自动播放 
	 
} 
 
void CPlayMediaView::OnOperStopa()  
{ 
	// TODO: Add your command handler code here 
	m_Music->GetControls().stop();//停止播放 
	 
} 
 
void CPlayMediaView::OnSize(UINT nType, int cx, int cy)  
{ 
	CView::OnSize(nType, cx, cy); 
	 
	// TODO: Add your message handler code here 
	/// 
	CRect rect; 
	GetClientRect(rect); 
	m_Video->MoveWindow(rect); 
	 
}