mplayerdlg.cpp

来自「c++系统开发实例精粹内附的80例源代码 环境:windows2000,c++」· C++ 代码 · 共 737 行 · 第 1/2 页

CPP
737 行
字号
// 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); //功能按扭使能控制
	//装载快捷键表
	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
	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 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()
{
	//窗口大小
	SetWindowPos(NULL,0,0,MPLAYERWIDTH,MPLAYERHEIGHT,SWP_NOZORDER|SWP_NOMOVE);
	//设置窗口标题
	ModifyStyle(0,WS_SYSMENU); //add an icon on the task bar
	SetWindowText(" 多媒体播放器 ");

	//信息按扭
	m_btnInfo.MoveWindow(1,1,26,10);//移动到位图上对应的位置
	m_btnInfo.SetTooltipText("关于多媒体播放器");
	m_btnInfo.DrawTransparent();//使按扭透明,以显示背景位图

	//关闭按扭
	m_btnClose.MoveWindow(240,1,8,9);
	m_btnClose.SetTooltipText("关闭");
	m_btnClose.DrawTransparent();

	//最小化按扭
	m_btnMiniWnd.MoveWindow(218,1,10,9);
	m_btnMiniWnd.SetTooltipText("最小化");
	m_btnMiniWnd.DrawTransparent();

	//打开文件按扭
	m_btnOpen.MoveWindow(17,64,18,12);
	m_btnOpen.SetTooltipText("选择文件");
	m_btnOpen.DrawTransparent();

	//播放按扭
	m_btnPlay.MoveWindow(37,57,25,25);
	m_btnPlay.SetTooltipText("播放");
	m_btnPlay.DrawTransparent();

	//暂停按扭
	m_btnPause.MoveWindow(64,63,18,12);
	m_btnPause.SetTooltipText("暂停");
	m_btnPause.DrawTransparent();

	//停止按扭
	m_btnStop.MoveWindow(87,63,18,12);
	m_btnStop.SetTooltipText("停止");
	m_btnStop.DrawTransparent();

	//声音增加
	m_btnVolDec.MoveWindow(156,63,29,14);
	m_btnVolDec.SetTooltipText("减少音量");
	m_btnVolDec.DrawTransparent();

	//声音减少
	m_btnVolInc.MoveWindow(188,63,29,14);
	m_btnVolInc.SetTooltipText("增加音量");
	m_btnVolInc.DrawTransparent();
	
	//全屏按扭
	m_btnFullScreen.MoveWindow(225,61,18,18);
	m_btnFullScreen.SetTooltipText("全屏");
	m_btnFullScreen.DrawTransparent();

	//进度条
	m_sld.MoveWindow(15,42,227,16);
	m_sld.SetThumbColors(0x008FA6F4,0x00FDE2D8);

	//液晶显示
	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_lcd.SetAutoPadding(true, '.');			//demonstrates auto padding with different character
	m_lcd.DoScroll(200, CMatrixStatic::LEFT);

	//扩展列表按扭
	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("显示文件列表");
	bExt=FALSE;
	//list control
	m_list.MoveWindow(2,91,244,111);

	//增加列表文件按扭
	m_btnListAdd.MoveWindow(3,205,37,12);
	m_btnListAdd.SetTooltipText("添加文件到列表");
	m_btnListAdd.DrawTransparent();

	//移除列表文件按扭
	m_btnListRemove.MoveWindow(44,205,48,12);
	m_btnListRemove.SetTooltipText("从列表中移除文件");
	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();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?