📄 ceplayerdlg.cpp
字号:
// CEPlayerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CEPlayer.h"
#include "CEPlayerDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCEPlayerDlg dialog
CCEPlayerDlg::CCEPlayerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCEPlayerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCEPlayerDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
mFilterGraph = NULL;
mSourceFile = "";
mSliderTimer = 0;
}
void CCEPlayerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCEPlayerDlg)
DDX_Control(pDX, IDC_STATIC_VIDEO, mVideoWindow);
DDX_Control(pDX, IDC_SLIDER1, mSliderGraph);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCEPlayerDlg, CDialog)
//{{AFX_MSG_MAP(CCEPlayerDlg)
ON_BN_CLICKED(IDC_CEPLAYER_EXIT, OnCeplayerExit)
ON_BN_CLICKED(IDC_CEPLAYER_OPEN, OnCeplayerOpen)
ON_BN_CLICKED(IDC_CEPLAYER_PLAY, OnCeplayerPlay)
ON_BN_CLICKED(IDC_CEPLAYER_PAUSE, OnCeplayerPause)
ON_BN_CLICKED(IDC_CEPLAYER_STOP, OnCeplayerStop)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCEPlayerDlg message handlers
BOOL CCEPlayerDlg::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
mVideoWindow.ModifyStyle(0, WS_CLIPCHILDREN);
// TODO: Add extra initialization here
mSliderGraph.SetRange(0, 1000);
mSliderGraph.SetPos(0);
return TRUE; // return TRUE unless you set the focus to a control
}
void CCEPlayerDlg::OnCeplayerExit()
{
// TODO: Add your control notification handler code here
OnOK();
}
void CCEPlayerDlg::OnCeplayerOpen()
{
// TODO: Add your control notification handler code here
CString strFilter = "AVI File (*.avi)|*.avi|";
strFilter += "MPEG File (*.mpg;*.mpeg)|*.mpg;*.mpeg|";
strFilter += "Mp3 File (*.mp3)|*.mp3|";
strFilter += "Wave File (*.wav)|*.wav|";
strFilter += "All Files (*.*)|*.*|";
CFileDialog dlgOpen(TRUE, NULL, NULL, OFN_PATHMUSTEXIST | OFN_HIDEREADONLY,
strFilter, this);
if (IDOK == dlgOpen.DoModal())
{
mSourceFile = dlgOpen.GetPathName();
// Rebuild the file playback filter graph
CreateGraph();
}
}
void CCEPlayerDlg::OnCeplayerPlay()
{
// TODO: Add your control notification handler code here
if (mFilterGraph)
{
mFilterGraph->Run();
// Start a timer
if (mSliderTimer == 0)
{
mSliderTimer = SetTimer(SLIDER_TIMER, 100, NULL);
}
}
}
void CCEPlayerDlg::OnCeplayerPause()
{
// TODO: Add your control notification handler code here
if (mFilterGraph)
{
mFilterGraph->Pause();
// Start a timer
if (mSliderTimer == 0)
{
mSliderTimer = SetTimer(SLIDER_TIMER, 100, NULL);
}
}
}
void CCEPlayerDlg::OnCeplayerStop()
{
// TODO: Add your control notification handler code here
if (mFilterGraph)
{
mFilterGraph->SetCurrentPosition(0);
mFilterGraph->Stop();
// Stop the timer
if (mSliderTimer)
{
KillTimer(mSliderTimer);
mSliderTimer = 0;
}
}
}
void CCEPlayerDlg::CreateGraph()
{
DestroyGraph();
mFilterGraph = new CDXGraph();
if (mFilterGraph->Create())
{
// Render the source clip
mFilterGraph->RenderFile(mSourceFile);
// Set video window and notification window
mFilterGraph->SetDisplayWindow(mVideoWindow.GetSafeHwnd());
mFilterGraph->SetNotifyWindow(this->GetSafeHwnd());
// Show the first frame
mFilterGraph->Pause();
}
}
void CCEPlayerDlg::DestroyGraph()
{
if (mFilterGraph)
{
// Stop the filter graph first
mFilterGraph->Stop();
mFilterGraph->SetNotifyWindow(NULL);
delete mFilterGraph;
mFilterGraph = NULL;
}
}
void CCEPlayerDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if (nIDEvent == mSliderTimer && mFilterGraph)
{
double pos = 0, duration = 1.;
mFilterGraph->GetCurrentPosition(&pos);
mFilterGraph->GetDuration(&duration);
// Get the new position, and update the slider
int newPos = int(pos * 1000 / duration);
if (mSliderGraph.GetPos() != newPos)
{
mSliderGraph.SetPos(newPos);
}
}
CDialog::OnTimer(nIDEvent);
}
CCEPlayerDlg::~CCEPlayerDlg()
{
DestroyGraph();
}
BOOL CCEPlayerDlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
if (mSliderTimer)
{
KillTimer(mSliderTimer);
mSliderTimer = 0;
}
return CDialog::DestroyWindow();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -