PlayerDlg.cpp
资源名称:Player.rar [点击查看]
上传用户:ziniusheji
上传日期:2022-08-10
资源大小:11534k
文件大小:9k
源码类别:
多媒体编程
开发平台:
C++ Builder
- // PlayerDlg.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "Player.h"
- #include "PlayerDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // 对话框数据
- enum { IDD = IDD_ABOUTBOX };
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
- // 实现
- protected:
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- END_MESSAGE_MAP()
- // CPlayerDlg 对话框
- CPlayerDlg::CPlayerDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CPlayerDlg::IDD, pParent)
- {
- m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON2);
- }
- void CPlayerDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_ACTIVEMOVIECONTROL1, m_amovie);
- }
- BEGIN_MESSAGE_MAP(CPlayerDlg, CDialog)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- //}}AFX_MSG_MAP
- // ON_BN_CLICKED(IDC_OPEN, &CPlayerDlg::OnBnClickedOpen)
- // ON_BN_CLICKED(IDC_START, &CPlayerDlg::OnBnClickedStart)
- ON_COMMAND(ID_PLAYSTOP, OnPlaystop)
- ON_COMMAND(ID_OPEN,OnOpen)
- ON_COMMAND(ID_PLAY,OnPlay)
- ON_COMMAND(ID_PAUSE,OnPause)
- ON_COMMAND(ID_EXIT,OnExit)
- ON_COMMAND(ID_CLOSE,OnClose)
- ON_COMMAND(ID_VEDIOFULL,OnVedioFull)
- ON_COMMAND(ID_VEDIO1,OnVedio1)
- ON_COMMAND(ID_CCTV1,OnCctv1)
- END_MESSAGE_MAP()
- // CPlayerDlg 消息处理程序
- BOOL CPlayerDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // 将“关于...”菜单项添加到系统菜单中。
- // IDM_ABOUTBOX 必须在系统命令范围内。
- 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);
- }
- }
- //把菜单加进对话框里面
- /*CMenu MyMenu3;
- MyMenu3.LoadMenu(IDR_MENU);//IDR_MENU是菜单的资源ID。
- this->SetMenu(&MyMenu3);
- MyMenu3.Detach(); */
- // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
- // 执行此操作
- SetIcon(m_hIcon, TRUE); // 设置大图标
- SetIcon(m_hIcon, FALSE); // 设置小图标
- // TODO: 在此添加额外的初始化代码
- return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
- }
- void CPlayerDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // 如果向对话框添加最小化按钮,则需要下面的代码
- // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
- // 这将由框架自动完成。
- void CPlayerDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // 用于绘制的设备上下文
- SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
- // 使图标在工作区矩形中居中
- 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;
- // 绘制图标
- dc.DrawIcon(x, y, m_hIcon);
- }
- else//添加背景图图片代码:
- {
- CDialog::OnPaint();//禁止这个调用
- /*CPaintDC dc(this);
- CRect rect;
- GetClientRect(&rect);
- CDC dcMem;
- dcMem.CreateCompatibleDC(&dc);
- CBitmap bmpBackground;
- bmpBackground.LoadBitmap(IDC_ACTIVEMOVIECONTROL1);
- //IDB_BITMAP是你自己的图对应的ID
- BITMAP bitmap;
- bmpBackground.GetBitmap(&bitmap);
- CBitmap *pbmpOld=dcMem.SelectObject(&bmpBackground);
- dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY); */
- }
- }
- //当用户拖动最小化窗口时系统调用此函数取得光标
- //显示。
- HCURSOR CPlayerDlg::OnQueryDragIcon()
- {
- return static_cast<HCURSOR>(m_hIcon);
- }
- void CPlayerDlg::OnOpen()
- {
- CFileDialog dlg(TRUE,NULL,NULL,0,"所有文件|*.*",NULL);
- if(dlg.DoModal()==IDOK)
- {
- m_amovie.SetFileName(dlg.GetPathName());
- }
- // TODO: 在此添加控件通知处理程序代码
- }
- void CPlayerDlg::OnPlay()
- {
- m_amovie.Run();
- }
- void CPlayerDlg::OnPause()
- {
- m_amovie.Pause();
- }
- void CPlayerDlg::OnPlaystop()
- {
- m_amovie.Stop();
- }
- void CPlayerDlg::OnClose()
- {
- m_amovie.SetFileName("");
- }
- void CPlayerDlg::OnExit()
- {
- OnCancel();
- }
- void CPlayerDlg::MoveMovieWindow()
- {
- //改变窗口大小以适应控件大小
- /*CRect rc1,rc2,rc3,rect;
- int woc;
- //得到ActiveMovie控件大小
- GetWindowRect( &rect );
- if(m_amovie.GetSafeHwnd())
- {
- m_amovie.MoveWindow(CRect(0,22,rect.Width(),rect.Height()-20),TRUE);
- }
- //HWND hwndChild=::GetWindow((HWND)IDC_ACTIVEMOVIECONTROL1,GW_CHILD);
- //woc=::GetDlgCtrlID(hwndChild);//取得ID
- /*m_amovie.GetWindowRect(&rc1);
- //保证对话框客户区的宽不小于300象素,高不小于225象素
- if(rc1.Width()<300||rc1.Height()<255)
- {
- rc1.right=rc1.left+300;
- rc1.bottom=rc1.top+225;
- }
- //获得对话框的大小
- GetWindowRect(&rc2);
- //获得对话框客户区大小
- GetClientRect(&rc3);
- //改变对话框大小以适应ActiveMovie控件大小
- MoveWindow(rc2.left,rc2.top,rc2.Width()-rc3.Width()+rc1.Width(),
- rc2.Height()-rc3.Height()+rc1.Height());
- //获得控件ActiveMovie的大小
- m_amovie.GetWindowRect(&rc1);
- GetClientRect(&rc3);
- //使ActiveMovie控件在对话框的客户区居中
- m_amovie.MoveWindow((rc3.Width()-rc1.Width())/2,
- (rc3.Height()-rc1.Height())/2,rc1.Width(),rc1.Height());*/
- }
- BEGIN_EVENTSINK_MAP(CPlayerDlg, CDialog)
- //{{AFX_EVENTSINK_MAP(CPlayerDlg)
- //}}AFX_EVENTSINK_MAP
- ON_EVENT(CPlayerDlg, IDC_ACTIVEMOVIECONTROL1, 1, CPlayerDlg::StateChangeActivemoviecontrol1, VTS_I4 VTS_I4)
- //ON_EVENT(CPlayerDlg, IDC_ACTIVEMOVIECONTROL1, DISPID_READYSTATECHANGE, CPlayerDlg::ReadyStateChangeActivemoviecontrol1, VTS_I4)
- ON_EVENT(CPlayerDlg, IDC_ACTIVEMOVIECONTROL1, 51, CPlayerDlg::DisplayModeChangeActivemoviecontrol1, VTS_NONE)
- ON_EVENT(CPlayerDlg, IDC_ACTIVEMOVIECONTROL1, 999, CPlayerDlg::ErrorActivemoviecontrol1, VTS_I2 VTS_BSTR VTS_BSTR VTS_PBOOL)
- ON_EVENT(CPlayerDlg, IDC_ACTIVEMOVIECONTROL1, 50, CPlayerDlg::OpenCompleteActivemoviecontrol1, VTS_NONE)
- END_EVENTSINK_MAP()
- void CPlayerDlg::OnVedio1()//视频的2倍
- {
- m_amovie.Pause();
- m_amovie.SetMovieWindowSize(1);
- m_amovie.Run();
- }
- void CPlayerDlg::OnVedioFull()//全屏
- {
- m_amovie.Pause();
- m_amovie.SetFullScreenMode(TRUE);
- m_amovie.Run();
- }
- // This OnCtlColor handler will change the color of a static control
- // with the ID of IDC_MYSTATIC. The code assumes that the CPenWidthsDlg
- // class has an initialized and created CBrush member named m_brush.
- // The control will be painted with red text and a background
- // color of m_brush.
- HBRUSH CPlayerDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- // Call the base class implementation first! Otherwise, it may
- // undo what we're trying to accomplish here.
- HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
- // Are we painting the IDC_MYSTATIC control? We can use
- // CWnd::GetDlgCtrlID() to perform the most efficient test.
- if (pWnd->GetDlgCtrlID() == IDC_ACTIVEMOVIECONTROL1)
- {
- // Set the text color to red
- pDC->SetTextColor(RGB(255, 0, 0));
- // Set the background mode for text to transparent
- // so background will show thru.
- pDC->SetBkMode(TRANSPARENT);
- // Return handle to our CBrush object
- hbr = m_brush;
- }
- return hbr;
- }
- void CPlayerDlg::OnDestroy()
- {
- CDialog::OnDestroy();
- // Free the space allocated for the background brush
- delete m_pEditBkBrush;
- }
- void CPlayerDlg::StateChangeActivemoviecontrol1(long oldState, long newState)
- {
- MoveMovieWindow();
- // TODO: 在此处添加消息处理程序代码
- }
- void CPlayerDlg::ReadyStateChangeActivemoviecontrol1(long ReadyState)
- {
- MoveMovieWindow();
- // TODO: 在此处添加消息处理程序代码
- }
- void CPlayerDlg::DisplayModeChangeActivemoviecontrol1()
- {
- MoveMovieWindow();
- // TODO: 在此处添加消息处理程序代码
- }
- void CPlayerDlg::ErrorActivemoviecontrol1(short SCode, LPCTSTR Description, LPCTSTR Source, BOOL* CancelDisplay)
- {
- CString str;
- str.Format("出现错误[%d]:nn%s",SCode,Description);
- MessageBox(str);
- *CancelDisplay=TRUE;
- // TODO: 在此处添加消息处理程序代码
- }
- void CPlayerDlg::OpenCompleteActivemoviecontrol1()
- {
- m_amovie.Run();
- // TODO: 在此处添加消息处理程序代码
- }
- void CPlayerDlg::OnCctv1()
- {
- m_amovie.SetFileName("mms://218.19.175.167:1755/stv4 ");
- }