www.pudn.com > MPlayer0623.zip > MPlayerDlg.cpp
// MPlayerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MPlayer.h"
#include "MPlayerDlg.h"
//#include "AlexfMixer.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CMPlayerDlg dialog
CMPlayerDlg::CMPlayerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMPlayerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMPlayerDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
bOpened=FALSE;
m_currentFrame=0;
bFirstPlay=FALSE;
iZoom=DOUBLESIZE; //for fullscreen button
m_totalSec=0;
m_curPlaySec=0;
m_totalFiles=0;
m_iList=0;
}
CMPlayerDlg::~CMPlayerDlg()
{
if(bOpened)
m_media.Close();
}
void CMPlayerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMPlayerDlg)
DDX_Control(pDX, IDC_LIST, m_list);
DDX_Control(pDX, IDC_INFO, m_btnInfo);
DDX_Control(pDX, IDCANCEL, m_btnClose);
DDX_Control(pDX, IDC_MINIWND, m_btnMiniWnd);
DDX_Control(pDX, IDC_OPEN, m_btnOpen);
DDX_Control(pDX, IDC_PLAY, m_btnPlay);
DDX_Control(pDX, IDC_PAUSE, m_btnPause);
DDX_Control(pDX, IDC_STOP, m_btnStop);
DDX_Control(pDX, IDC_VOLINC, m_btnVolInc);
DDX_Control(pDX, IDC_VOLDEC, m_btnVolDec);
DDX_Control(pDX, IDC_FULLSCREEN, m_btnFullScreen);
DDX_Control(pDX, IDC_SLIDER, m_sld);
DDX_Control(pDX, IDC_LCD, m_lcd);
DDX_Control(pDX, IDC_EXT, m_btnExt);
DDX_Control(pDX, IDC_LISTADD, m_btnListAdd);
DDX_Control(pDX, IDC_LISTREMOVE, m_btnListRemove);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMPlayerDlg, CDialog)
//{{AFX_MSG_MAP(CMPlayerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_ERASEBKGND()
ON_WM_LBUTTONDOWN()
ON_BN_CLICKED(IDC_MINIWND, OnMiniwnd)
ON_BN_CLICKED(IDC_INFO, OnInfo)
ON_BN_CLICKED(IDC_OPEN, OnOpen)
ON_BN_CLICKED(IDC_PLAY, OnPlay)
ON_BN_CLICKED(IDC_FULLSCREEN, OnFullscreen)
ON_BN_CLICKED(IDC_STOP, OnStop)
ON_BN_CLICKED(IDC_PAUSE, OnPause)
ON_BN_CLICKED(IDC_VOLINC, OnVolinc)
ON_WM_TIMER()
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER, OnReleasedcaptureSlider)
ON_BN_CLICKED(IDC_EXT, OnExt)
ON_LBN_DBLCLK(IDC_LIST, OnDblclkList)
ON_BN_CLICKED(IDC_LISTADD, OnListAdd)
ON_BN_CLICKED(IDC_LISTREMOVE, OnListRemove)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_VOLDEC, OnVolDec)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMPlayerDlg message handlers
BOOL CMPlayerDlg::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
InitMPlayerFace();
UpdateWindowEx(bOpened);
//load accelerator table
m_hAccelTable=LoadAccelerators(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_ACCER));
OpenList();
return TRUE; // return TRUE unless you set the focus to a control
}
void CMPlayerDlg::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 CMPlayerDlg::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 CMPlayerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CMPlayerDlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
// load MPlayer background face (bmp)
CDC memDC;
CBitmap MPlayer;
if(!MPlayer.LoadBitmap(IDB_MPLAYER))
return FALSE;
memDC.CreateCompatibleDC(pDC);
CBitmap *pOldBmp=memDC.SelectObject(&MPlayer);
pDC->BitBlt(0,0,MPLAYERWIDTH,MPLAYEREXT,&memDC,0,0,SRCCOPY);
memDC.SelectObject(pOldBmp);
// return CDialog::OnEraseBkgnd(pDC);
return TRUE;
}
void CMPlayerDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//post message to make the mouse can draw/drag the dialog
PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM (point.x, point.y));
CDialog::OnLButtonDown(nFlags, point);
}
void CMPlayerDlg::InitMPlayerFace()
{
//window size
SetWindowPos(NULL,0,0,MPLAYERWIDTH,MPLAYERHEIGHT,SWP_NOZORDER|SWP_NOMOVE);
//window text
ModifyStyle(0,WS_SYSMENU); //add an icon on the task bar
SetWindowText(" MPlayer ");
//info button
m_btnInfo.MoveWindow(1,1,26,10);
m_btnInfo.SetTooltipText("Info about the MPlayer");
// m_btnInfo.SetIcon(IDR_MAINFRAME);
m_btnInfo.DrawTransparent();
//close button
m_btnClose.MoveWindow(240,1,8,9);
m_btnClose.SetTooltipText("close MPlayer");
m_btnClose.DrawTransparent();
//mini window button
m_btnMiniWnd.MoveWindow(218,1,10,9);
m_btnMiniWnd.SetTooltipText("Mini MPlayer");
m_btnMiniWnd.DrawTransparent();
//open button
m_btnOpen.MoveWindow(17,64,18,12);
m_btnOpen.SetTooltipText("Select file");
m_btnOpen.DrawTransparent();
//play button
m_btnPlay.MoveWindow(37,57,25,25);
m_btnPlay.SetTooltipText("Play");
m_btnPlay.DrawTransparent();
//pause button
m_btnPause.MoveWindow(64,63,18,12);
m_btnPause.SetTooltipText("Pause");
m_btnPause.DrawTransparent();
//stop button
m_btnStop.MoveWindow(87,63,18,12);
m_btnStop.SetTooltipText("Stop");
m_btnStop.DrawTransparent();
//vol decrease button
m_btnVolDec.MoveWindow(156,63,29,14);
m_btnVolDec.SetTooltipText("Decrease Volume");
m_btnVolDec.DrawTransparent();
//vol increase button
m_btnVolInc.MoveWindow(188,63,29,14);
m_btnVolInc.SetTooltipText("Increase Volume");
m_btnVolInc.DrawTransparent();
//fullscreen button
m_btnFullScreen.MoveWindow(225,61,18,18);
m_btnFullScreen.SetTooltipText("Full Screen");
m_btnFullScreen.DrawTransparent();
//progress slider
m_sld.MoveWindow(15,42,227,16);
m_sld.SetThumbColors(0x008FA6F4,0x00FDE2D8);
//set lcd text
m_lcd.MoveWindow(5,17,60,20);
m_lcd.SetNumberOfLines(1);
m_lcd.SetXCharsPerLine(11);
m_lcd.SetSize(CMatrixStatic::TINY);
m_lcd.SetDisplayColors(RGB(0, 0, 0), 0x007FFF40, RGB(103, 30, 0));
m_lcd.AdjustClientXToSize(8);
m_lcd.AdjustClientYToSize(1);
m_lcd.SetText(_T("M-Player"));
m_lcd.SetAutoPadding(true, '.'); //demonstrates auto padding with different character
m_lcd.DoScroll(200, CMatrixStatic::LEFT);
//set extend button
m_btnExt.MoveWindow(4,65,10,10);
m_btnExt.SetBitmaps(IDB_EXT,NULL,NULL);
m_btnExt.SetFlat();
m_btnExt.SetColor( CButtonST::BTNST_COLOR_BK_IN,0x00FD0C00);
m_btnExt.SetTooltipText("Show Media File Lists");
bExt=FALSE;
//list control
m_list.MoveWindow(2,91,244,111);
//list add button
m_btnListAdd.MoveWindow(3,205,37,12);
m_btnListAdd.SetTooltipText("Add Files to the media lists");
m_btnListAdd.DrawTransparent();
//list remove button
m_btnListRemove.MoveWindow(44,205,48,12);
m_btnListRemove.SetTooltipText("Remove Files from the media lists");
m_btnListRemove.DrawTransparent();
}
void CMPlayerDlg::OnMiniwnd()
{
// TODO: Add your control notification handler code here
ShowWindow(SW_MINIMIZE);
}
void CMPlayerDlg::OnInfo()
{
// TODO: Add your control notification handler code here
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
void CMPlayerDlg::OnOpen()
{
// TODO: Add your control notification handler code here
if(!OpenFiles())
return;
OnPlay(); //call OnPlay() function to play
}
void CMPlayerDlg::OnPlay()
{
// TODO: Add your control notification handler code here
if(!m_totalFiles) //no media file in the list
if(!OpenFiles()) //cancel open
return;
Play();
}
void CMPlayerDlg::UpdateWindowEx(bool bOpened)
{
m_btnFullScreen.EnableWindow(bOpened);
m_btnPause.EnableWindow(bOpened);
// m_btnPlay.EnableWindow(bOpened);
m_btnStop.EnableWindow(bOpened);
m_btnVolDec.EnableWindow(bOpened);
m_btnVolInc.EnableWindow(bOpened);
m_sld.EnableWindow(bOpened);
}
void CMPlayerDlg::OnFullscreen()
{
// TODO: Add your control notification handler code here
if(!bIsVideo)
return;
CWnd *pMediaWnd=GetMediaWnd();
/////////// for release virsion debug/////////////
// CString strHandle;
// strHandle.Format("%d",pMediaWnd);
// AfxMessageBox(strHandle);
//////////////////////////////////////////////////
LONG widthWnd=m_mediaWndRect.right-m_mediaWndRect.left;
LONG heightWnd=m_mediaWndRect.bottom-m_mediaWndRect.top;
switch(iZoom){
case NORMALSIZE:
pMediaWnd->ShowWindow(SW_SHOWNORMAL);
pMediaWnd->ModifyStyle(0,WS_CAPTION);
pMediaWnd->MoveWindow(&m_mediaWndRect);
iZoom=DOUBLESIZE;
break;
case DOUBLESIZE:
pMediaWnd->MoveWindow(0,0,widthWnd*2,heightWnd*2);
iZoom=FULLSCREEN;
break;
case FULLSCREEN:
m_media.SetFullScreen();
iZoom=NORMALSIZE;
break;
}
}
void CMPlayerDlg::OnStop()
{
// TODO: Add your control notification handler code here
m_media.Stop();
m_curPlayTime.min=(UINT)0;
m_curPlayTime.sec=(UINT)0;
m_lcd.SetText(_T("Stop 00;00"));
m_sld.SetPos(0);
KillTimer(m_nTimer);
}
void CMPlayerDlg::OnPause()
{
// TODO: Add your control notification handler code here
m_media.Pause();
bPause=!bPause;
CString strTime;
if(bPause)
{
KillTimer(m_nTimer);
strTime.Format("Pause %2d;%2d",m_curPlayTime.min,m_curPlayTime.sec);
}else
{ //continue
m_nTimer = SetTimer(1, 1000, 0);
strTime.Format("Play %2d;%2d",m_curPlayTime.min,m_curPlayTime.sec);
}
m_lcd.SetText(strTime);
}
void CMPlayerDlg::InitSlider()
{
m_curPlaySec=0;
m_totalSec=m_media.GetTotalSec();
m_sld.SetRange(0,m_totalSec);
m_sld.SetTicFreq(1);
}
CWnd* CMPlayerDlg::GetMediaWnd()
{
return FromHandle(m_media.GetHwnd());
}
void CMPlayerDlg::OnVolinc()
{
// TODO: Add your control notification handler code here
// static int iFactor=10000;
m_media.SetVolume(1);
// iFactor+=100;
ShellExecute(this->m_hWnd, "open", "sndvol32.exe", NULL, NULL, SW_SHOWNORMAL);
}
void CMPlayerDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CString dispText;
TimeIncToStr(dispText);
m_lcd.SetText((LPCTSTR)dispText);
///set slider
if(m_curPlaySec==m_totalSec)
{
if(m_totalFiles>1) //play next media
{
m_iList++;
Play();
}else //else stop , not cycle
{
OnStop();
return;
}
}
m_curPlaySec++;
m_sld.SetPos(m_curPlaySec);
CDialog::OnTimer(nIDEvent);
}
void CMPlayerDlg::TimeIncToStr(CString &strTime)
{
m_curPlayTime.sec++;
if(m_curPlayTime.sec>=60)
{
m_curPlayTime.min++;
m_curPlayTime.sec=(UINT)0;
}
strTime.Format("Play %2d;%2d",m_curPlayTime.min,m_curPlayTime.sec);
}
void CMPlayerDlg::OnReleasedcaptureSlider(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
m_curPlaySec=m_sld.GetPos();
m_curPlayTime.min=m_curPlaySec/60;
m_curPlayTime.sec=m_curPlaySec%60;
if(bIsVideo) //video media
{
m_currentFrame=m_curPlaySec*m_frameRate;
m_media.Play(m_currentFrame); //play from new frame
}else //music media
{
m_media.Play(m_curPlaySec*1000); //play from new position in milliseconds
}
*pResult = 0;
}
void CMPlayerDlg::OnExt()
{
// TODO: Add your control notification handler code here
if(!bExt) //not in extended state ,then ext
{
SetWindowPos(0,0,0,MPLAYERWIDTH,MPLAYEREXT,SWP_NOZORDER|SWP_NOMOVE);
m_btnExt.SetBitmaps(IDB_N_EXT,NULL,NULL);
m_btnExt.SetTooltipText("Hide Media File Lists");
}
else //resume the orignal window
{
SetWindowPos(0,0,0,MPLAYERWIDTH,MPLAYERHEIGHT,SWP_NOZORDER|SWP_NOMOVE);
m_btnExt.SetBitmaps(IDB_EXT,NULL,NULL);
m_btnExt.SetTooltipText("Show Media File Lists");
}
bExt=!bExt;
}
void CMPlayerDlg::OnDblclkList()
{
// TODO: Add your control notification handler code here
m_iList=m_list.GetCurSel();
OnPlay();
}
bool CMPlayerDlg::OpenFiles(bool bListAdd)
{
//open files and add to list
CFileDialog FileDlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR,
_OPENTYPE);
if(FileDlg.DoModal()!=IDOK)
return FALSE;
if(!bListAdd)
m_list.ResetContent();
POSITION pos=FileDlg.GetStartPosition();
CString lpszFile;
lpszFile=FileDlg.GetNextPathName(pos);
while(1)
{
m_list.AddString(lpszFile);
if(!pos) break;
lpszFile=FileDlg.GetNextPathName(pos);
}
m_iList=0;
m_totalFiles=m_list.GetCount();
return TRUE;
}
bool CMPlayerDlg::Play()
{
if(bOpened) //close previous media
{
m_media.Close();
bOpened=FALSE;
}
CString strError;
m_list.SetSel(m_iList-1,FALSE);
if(m_iList==m_totalFiles) //list pointer flow out
m_iList=0;
m_list.SetSel(m_iList,TRUE);
m_list.GetText(m_iList,m_curFile);
m_media.Create(m_curFile,strError);
if(strError!="OK")
{
#if _DEBUG
AfxMessageBox(strError); //get error message
#endif
CString errorMsg;
errorMsg="Can not open file: ";
errorMsg+=m_curFile;
AfxMessageBox(errorMsg);
return FALSE;
}
/////////////////////////////////
bFirstPlay=TRUE; //first play the media
BeginWaitCursor();
m_media.Play(0); //play from 0 position
// get orginal size of Media window
bIsVideo=m_media.IsVideo();
if(bFirstPlay && bIsVideo) //first play the media ,get the orginal window rectangle size
{
CWnd* pMediaWnd=GetMediaWnd();
pMediaWnd->GetWindowRect(&m_mediaWndRect);
iZoom=DOUBLESIZE;
bFirstPlay=FALSE;
}
//update window
bOpened=TRUE;
bPause=FALSE;
UpdateWindowEx(bOpened);
InitSlider(); //initialize the slider bar
//////set the timer, 1 second interval
m_nTimer = SetTimer(1, 1000, 0);
m_curPlayTime.min=(UINT)0;
m_curPlayTime.sec=(UINT)0;
// m_lcd.AdjustClientXToSize(10);
m_lcd.SetText(_T("Play 00;00"));
m_lcd.StopScroll();
//////////// get framerate if video file
if(bIsVideo)
m_frameRate=m_media.GetFrameRate();
else
m_frameRate=0;
EndWaitCursor();
return TRUE;
}
void CMPlayerDlg::OnListAdd()
{
// TODO: Add your control notification handler code here
OpenFiles(1);
}
void CMPlayerDlg::OnListRemove()
{
// TODO: Add your control notification handler code here
int selectCounts=m_list.GetSelCount();
int* lpInt=new int[m_totalFiles+1];
//for(int i=0;im_hWnd, "open", "sndvol32.exe", NULL, NULL, SW_SHOWNORMAL);
/* CAlexfMixer mixer(this->m_hWnd, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,
NO_SOURCE, MIXERCONTROL_CONTROLTYPE_VOLUME);
if (!mixer.IsOk())
return;
mixer.SetControlValue(0);
*/ //no usefull
}