www.pudn.com > PlayMedia.rar > PlayMediaView.cpp
// PlayMediaView.cpp : implementation of the CPlayMediaView class
//
#include "stdafx.h"
#include "PlayMedia.h"
#include "PlayMediaDoc.h"
#include "PlayMediaView.h"
#include "wmpplayer4.h"
#include "wmpcontrols.h"
#include "wmpsettings.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_COMMAND(ID_OPER_OPENA, OnOperOpena)
ON_COMMAND(ID_OPER_OPENV, OnOperOpenv)
ON_COMMAND(ID_OPER_PLAYA, OnOperPlaya)
ON_COMMAND(ID_OPER_PLAYV, OnOperPlayv)
ON_COMMAND(ID_OPER_STOPA, OnOperStopa)
ON_COMMAND(ID_OPER_STOPV, OnOperStopv)
ON_WM_CREATE()
//}}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
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::OnOperOpenv()
{
// TODO: Add your command handler code here
// 只允许打开视频文件
static char BASED_CODE szFilter[] = "Video Files (*.avi;*.mpg;*.mpeg)|*.avi;*.mpg;*.mpeg|";
CFileDialog fileDlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, szFilter);
if(fileDlg.DoModal() == IDOK){
// 获得视频文件名
m_strVideo = fileDlg.GetPathName();
}
}
void CPlayMediaView::OnOperPlaya()
{
// TODO: Add your command handler code here
// m_Music->Stop(); // 首先停止正在播放的
m_Music->SetAutoStart(TRUE); // 准备播放
m_Music->SetFileName(m_strMusic); // 载入视频文件自动播放
}
void CPlayMediaView::OnOperPlayv()
{
// TODO: Add your command handler code here
// m_Video->Stop(); // 首先停止正在播放的
m_Video->SetAutoStart(TRUE); // 准备播放
m_Video->SetFileName(m_strVideo); // 载入视频文件自动播放
}
void CPlayMediaView::OnOperStopa()
{
// TODO: Add your command handler code here
m_Music->Stop(); // 停止播放
}
void CPlayMediaView::OnOperStopv()
{
// TODO: Add your command handler code here
m_Video->Stop(); // 停止播放
}
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); // 获得标准箭头鼠标指针
CRect rect;
GetClientRect(rect); // 获得客户区大小
// 创建视频窗口
m_Video->Create(AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_PARENTDC, hCursor, 0, 0),
NULL, WS_VISIBLE|WS_CHILD, rect, this, 0);
// 由于使用单独的音频来播放,将视频设置为静音模式
m_Video->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;
}