📄 countautodlg.cpp
字号:
// CountAutoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CountAuto.h"
#include "CountAutoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define SLIDER_TIMER 100
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCountAutoDlg dialog
CCountAutoDlg::CCountAutoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCountAutoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCountAutoDlg)
m_bkGround = 0;
m_timespand=0;
m_timespance = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_FilterGraph=NULL;
m_SourseFile="";
m_SliderTimer=0;
m_duration=0;
m_IsTop=0;
}
void CCountAutoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCountAutoDlg)
DDX_Control(pDX, IDC_STATE, m_state);
DDX_Control(pDX, IDC_SLIDER1, m_mySlider);
DDX_Control(pDX, IDC_PLAY_WINDOW, m_VideoWindow);
DDX_Radio(pDX, IDC_RADIO_BKGROUND, m_bkGround);
DDX_Text(pDX, IDC_EDIT2, m_timespance);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCountAutoDlg, CDialog)
//{{AFX_MSG_MAP(CCountAutoDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_PLAY, OnBtnPlay)
ON_BN_CLICKED(IDC_BTN_PAUSE, OnBtnPause)
ON_BN_CLICKED(IDC_BTN_STOP, OnBtnStop)
ON_BN_CLICKED(IDC_BTN_GRAB, OnBtnGrab)
ON_BN_CLICKED(IDC_BTN_FULLSCREEN, OnBtnFullscreen)
ON_BN_CLICKED(IDC_BTN_OPEN, OnBtnOpen)
ON_WM_TIMER()
ON_WM_HSCROLL()
ON_WM_CANCELMODE()
ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
ON_WM_ERASEBKGND()
ON_COMMAND(IDM_TOP, OnTop)
ON_UPDATE_COMMAND_UI(IDM_TOP, OnUpdateTop)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_GRAPHNOTIFY,OnGraphNotify)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCountAutoDlg message handlers
BOOL CCountAutoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
m_FilterGraph=NULL;
VERIFY(m_play.AutoLoad(IDC_BTN_PLAY,this));
VERIFY(m_pause.AutoLoad(IDC_BTN_PAUSE,this));
VERIFY(m_stop.AutoLoad(IDC_BTN_STOP,this));
m_VideoWindow.ModifyStyle(0,WS_CLIPCHILDREN);
m_mySlider.SetRange(0,1000);
m_mySlider.SetPos(0);
return TRUE; // return TRUE unless you set the focus to a control
}
void CCountAutoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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 CCountAutoDlg::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 CCountAutoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCountAutoDlg::OnBtnPlay()
{
// TODO: Add your control notification handler code here
if(m_FilterGraph)
{
m_FilterGraph->Run();
// m_FilterGraph->RunGrabberGraph();
if(m_SliderTimer==0)
m_SliderTimer=SetTimer(SLIDER_TIMER,100,NULL);
if(m_GrabTimer==0)m_GrabTimer=SetTimer(1,m_timespance,NULL);
}
}
void CCountAutoDlg::OnBtnPause()
{
// TODO: Add your control notification handler code here
if(m_FilterGraph)
{
m_FilterGraph->Pause();
m_SliderTimer=SetTimer(SLIDER_TIMER,100,NULL);
}
}
void CCountAutoDlg::OnBtnStop()
{
// TODO: Add your control notification handler code here
if(m_FilterGraph)
{
m_FilterGraph->SetCurrentPosition(0);
m_FilterGraph->Stop();
if(m_SliderTimer)
{
KillTimer(m_SliderTimer);
m_SliderTimer=0;
m_mySlider.SetPos(0);
}
}
}
void CCountAutoDlg::OnBtnGrab()
{
// TODO: Add your control notification handler code here
if(m_FilterGraph)
{
char szTemp[]="C:\\mySnapshot.bmp";
unsigned char * buffer;
CDC *dc=(GetDlgItem(IDC_STATIC_DIVISIOIN))->GetDC();
HDC hdc=dc->GetSafeHdc();
if(m_FilterGraph->Snapshot(hdc,szTemp,buffer))
return ;
}
}
void CCountAutoDlg::OnBtnFullscreen()
{
// TODO: Add your control notification handler code here
if(m_FilterGraph)
{
m_FilterGraph->SetFullScreen(TRUE);
}
}
void CCountAutoDlg::CreateGraph()
{
DestroyGraph();
m_FilterGraph=new CDXGraph();
if(m_FilterGraph->Create())
{
/* m_FilterGraph->CreateSampleGrabber();
m_FilterGraph->SpecifyMediaType();
m_FilterGraph->CompleteBuildGraph(m_SourseFile);*/
m_FilterGraph->RenderFile(m_SourseFile);
m_FilterGraph->SetDisplayWindow(m_VideoWindow.GetSafeHwnd());
m_FilterGraph->SetNotifyWindow(this->GetSafeHwnd());
m_FilterGraph->Pause();
m_FilterGraph->GetDuration(&m_duration);
CWnd * hwnd=GetDlgItem(IDC_EDIT2);
hwnd->UpdateData(TRUE);
if(!m_timespance)m_timespance=m_duration*2;
//设置持续时间
m_helpH=(int)(m_duration/3600.0);
m_helpM=(((int)(m_duration))%3600)/60;
m_helpS=(int(m_duration-(m_helpH*3600+m_helpM*60)));
m_DHMS.Format("/%#02d:%#02d:%#02d",m_helpH,m_helpM,m_helpS);
CString text;
text="准备播放... 00:00:00"+m_DHMS;
m_state.SetWindowText(text);
}
}
void CCountAutoDlg::DestroyGraph()
{
if(m_FilterGraph)
{
m_FilterGraph->Stop();
m_FilterGraph->SetNotifyWindow(NULL);
delete m_FilterGraph;
m_FilterGraph=NULL;
}
}
void CCountAutoDlg::OnBtnOpen()
{
// TODO: Add your control notification handler code here
CString strFile;
strFile=".Avi Files(*.avi)|*.avi|";
strFile+="MPEG File(*.mpg;*.mpeg)|*.mpg;*.mpeg|";
strFile+="Mp3 File (*.mp3)|*.mp3|";
strFile+="Wave Files (*.wav)|*wav|";
strFile+="All Files (*.*)|*.*|";
CFileDialog filedlg(TRUE,NULL,NULL,OFN_PATHMUSTEXIST|OFN_HIDEREADONLY,
strFile,this);
if(IDOK==filedlg.DoModal())
{
m_SourseFile=filedlg.GetPathName();
CreateGraph();
}
}
void CCountAutoDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent==m_SliderTimer&&m_FilterGraph)
{
double pos=0;
m_FilterGraph->GetCurrentPosition(&pos);
UINT newPos=int(pos*1000.0/m_duration);
if(m_mySlider.GetPos()!=newPos)
m_mySlider.SetPos(newPos);
//设置播放状态
m_helpH=(int)(pos/3600.0);
m_helpM=(((int)(pos))%3600)/60;
m_helpS=(int(pos-(m_helpH*3600+m_helpM*60)));
CString text;
text.Format("%#02d:%#02d:%#02d",m_helpH,m_helpM,m_helpS);
text="正在播放 "+text+m_DHMS;
m_state.SetWindowText(text);
}
else if(nIDEvent==m_GrabTimer&&m_FilterGraph)
{
if(m_FilterGraph)
{
char szTemp[]="C:\\mySnapshot.bmp";
unsigned char * buffer;
CDC *dc=(GetDlgItem(IDC_STATIC_DIVISIOIN))->GetDC();
HDC hdc=dc->GetSafeHdc();
if(m_FilterGraph->Snapshot(hdc,szTemp,buffer))
return ;
}
}
CDialog::OnTimer(nIDEvent);
}
LRESULT CCountAutoDlg::OnGraphNotify(WPARAM inWParam,LPARAM inLParam)
{
IMediaEventEx *pEvent=NULL;
if(m_FilterGraph&&(pEvent=m_FilterGraph->GetEventHandle()))
{
LONG eventCode=0,eventParam1=0,eventParam2=0;
if(SUCCEEDED(pEvent->GetEvent(&eventCode,&eventParam1,&eventParam2,0)))
{
pEvent->FreeEventParams(eventCode,eventParam1,eventParam2);
switch(eventCode)
{
case EC_COMPLETE:
OnBtnPause();
m_FilterGraph->SetCurrentPosition(0);
break;
case EC_USERABORT:
case EC_ERRORABORT:
OnBtnStop();
default :break;
}
}
}
return 0;
}
BOOL CCountAutoDlg::RegisterFilter(const char *InFilterAx)
{
typedef (WINAPI* REGISTER_FUN) (void);
REGISTER_FUN MyFun=NULL;
HMODULE hModule=::LoadLibrary(InFilterAx);
if(hModule)
{
MyFun=(REGISTER_FUN)GetProcAddress(hModule,
"DllRegisterServer");
BOOL pas=(MyFun!=NULL);
if(pas)
{
MyFun();
}
::FreeLibrary(hModule);
return pas;
}
return FALSE;
}
void CCountAutoDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
if(m_mySlider.GetSafeHwnd()==pScrollBar->GetSafeHwnd())
{
if (m_FilterGraph)
{
// Calculate the current seeking position
double pos = m_duration * m_mySlider.GetPos() / 1000.;
m_FilterGraph->SetCurrentPosition(pos);
}
}
else
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CCountAutoDlg::OnCancelMode()
{
CDialog::OnCancelMode();
// TODO: Add your message handler code here
}
void CCountAutoDlg::OnChangeEdit2()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
CWnd * hwnd=GetDlgItem(IDC_EDIT2);
hwnd->UpdateData(TRUE);
if(m_GrabTimer==0&&m_timespance)m_GrabTimer=SetTimer(1,m_timespance,NULL);
else if(m_GrabTimer)
{
KillTimer(1);
m_GrabTimer=SetTimer(1,m_timespance,NULL);
}
}
BOOL CCountAutoDlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
m_VideoWindow.GetWindowRect(&rect);
ScreenToClient(&rect);
pDC->ExcludeClipRect(&rect);
return CDialog::OnEraseBkgnd(pDC);
}
void CCountAutoDlg::OnTop()
{
// TODO: Add your command handler code here
if(m_IsTop==0){
const CWnd *pWndInsertAfter;
pWndInsertAfter=&wndNoTopMost;
SetWindowPos(pWndInsertAfter,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE);
}
else
{
const CWnd * pWndInsertAfter;
pWndInsertAfter = &wndTopMost;
SetWindowPos(pWndInsertAfter,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE);
}
}
void CCountAutoDlg::OnUpdateTop(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(m_IsTop==0){
GetMenu()->GetSubMenu(0)->CheckMenuItem(0,MF_CHECKED|MF_BYPOSITION );
m_IsTop=1;
}
else
{
GetMenu()->GetSubMenu(0)->CheckMenuItem(0,MF_UNCHECKED|MF_BYPOSITION );
m_IsTop=0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -