📄 videobar.cpp
字号:
// VideoBar.cpp : implementation file
//
#include "stdafx.h"
#include "VideoBar.h"
#include "resource.h"
#include "vfw.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CVideoBar
CVideoBar::CVideoBar()
{
m_hwnd=NULL;
bl_play=false;
m_Path.Empty();
m_OldPath.Empty();
}
CVideoBar::~CVideoBar()
{
if(!m_OldPath.IsEmpty())
if((m_OldPath.Find(".rmvb")>-1)||(m_OldPath.Find(".m2v")>-1)||(m_OldPath.Find(".rm")>-1))
{
CFile::Rename(m_Path,m_OldPath);
m_OldPath=_T("");
}
}
BEGIN_MESSAGE_MAP(CVideoBar, baseCMyBar)
//{{AFX_MSG_MAP(CVideoBar)
ON_WM_CREATE()
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyBar message handlers
int CVideoBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (baseCMyBar::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndChild.Create(NULL,WS_CHILD|WS_VISIBLE|WS_BORDER,CRect(0,0,0,0),this,ID_VIDEOBAR))
return -1;
if (!m_open.Create("Open",WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,ID_OPEN))
return -1;
if (!m_play.Create("Play",WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,ID_PLAY))
return -1;
if (!m_close.Create("Close",WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,ID_CLOSE))
return -1;
return 0;
}
void CVideoBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
{
baseCMyBar::OnUpdateCmdUI(pTarget, bDisableIfNoHndler);
UpdateDialogControls(pTarget, bDisableIfNoHndler);
}
void CVideoBar::OnSize(UINT nType, int cx, int cy)
{
baseCMyBar::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
CRect rc;
GetClientRect(rc);
int x=rc.right;
int y=rc.bottom;
int width=rc.Width()/3;
int height=rc.Height();
if(height>=80)
height=20;
else height=height/4;
rc.bottom-=height+2;
m_wndChild.MoveWindow(rc);
rc.top=y-height;
rc.bottom=y;
int temp=rc.right=rc.left+width;
m_open.MoveWindow(rc);
rc.right=x;
rc.left=rc.right-width;
m_close.MoveWindow(rc);
rc.right=rc.left-1;
rc.left=temp+1;
m_play.MoveWindow(rc);
if(bl_play)
{
m_wndChild.GetClientRect(rc);
::MoveWindow(m_hwnd,rc.left,rc.top,rc.right,rc.bottom,true);
}
}
BOOL CVideoBar::OnOpen()
{
CFileDialog video(TRUE,NULL,NULL,OFN_HIDEREADONLY,"Video Files (*.avi *.wav *.mpeg)|*.avi;*.wav;*.mpeg|Other Video Files(*.mpg*.asf*.wmv*.rmvb*.rm*m2v)|*.mpg;*.asf;*.wmv;*.rmvb;*.rm;*m2v|Wave Files (*.wav*.wmv*.wma*.mid*.midi)|*.wav;*.wmv;*.wma;*mid;*.midi|MP3 Files (*.mp3)|*.mp3|Other Audio Files (*.mpga)|*.mpga|All File (*.*)|*.*|");
if(video.DoModal() == IDOK)
{
if(!m_OldPath.IsEmpty())
if((m_OldPath.Find(".rmvb")>-1)||(m_OldPath.Find(".m2v")>-1)||(m_OldPath.Find(".rm")>-1))
{
CFile::Rename(m_Path,m_OldPath);
m_OldPath=_T("");
}
m_Path = video.GetPathName();
CString temp=video.GetFileExt();
if(~(temp.Find("rmvb")&temp.Find("m2v")&temp.Find("rm")))
{
m_OldPath=m_Path;
m_Path+=".mpeg";
CFile::Rename(m_OldPath,m_Path);
}
OnClose();
OnPlay();
return true;
}
else return false;
}
void CVideoBar::OnClose()
{
MCIWndStop(m_hwnd);
if(m_hwnd !=NULL)
{
MCIWndDestroy(m_hwnd);
m_hwnd=NULL;
}
bl_play=false;
}
void CVideoBar::OnPlay()
{
if(!m_Path.IsEmpty())
{
if(m_hwnd == NULL)
m_hwnd = MCIWndCreate(m_wndChild.GetSafeHwnd(),
AfxGetInstanceHandle(),
WS_CHILD | WS_VISIBLE/*|MCIWNDF_NOMENU|MCIWNDF_SHOWMODE*/
,m_Path);
else
MCIWndHome(m_hwnd);
if(!m_OldPath.IsEmpty())
if((m_OldPath.Find(".rmvb")>-1)||(m_OldPath.Find(".m2v")>-1)||(m_OldPath.Find(".rm")>-1))
{
CFile::Rename(m_Path,m_OldPath);
m_OldPath=_T("");
}
CRect rc;
m_wndChild.GetClientRect(rc);
::MoveWindow(m_hwnd,rc.left,rc.top,rc.right,rc.bottom,true);
MCIWndPlay(m_hwnd);
::UpdateWindow(m_hwnd);;
bl_play=true;
}
else MessageBox("请先选择视屏或音频文件!","Warning",MB_OK|MB_ICONWARNING);
}
void CVideoBar::Open(CString fname,CString ext)
{
if(!m_OldPath.IsEmpty())
if((m_OldPath.Find(".rmvb")>-1)||(m_OldPath.Find(".m2v")>-1)||(m_OldPath.Find(".rm")>-1))
{
CFile::Rename(m_Path,m_OldPath);
m_OldPath=_T("");
}
m_Path = fname;
CString temp=ext;
if(~(temp.Find("rmvb")&temp.Find("m2v")&temp.Find("rm")))
{
m_OldPath=m_Path;
m_Path+=".mpeg";
CFile::Rename(m_OldPath,m_Path);
}
OnClose();
OnPlay();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -