PlayerDlg.cpp
上传用户:ziniusheji
上传日期:2022-08-10
资源大小:11534k
文件大小:9k
源码类别:

多媒体编程

开发平台:

C++ Builder

  1. // PlayerDlg.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "Player.h"
  5. #include "PlayerDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #endif
  9. // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
  10. class CAboutDlg : public CDialog
  11. {
  12. public:
  13. CAboutDlg();
  14. // 对话框数据
  15. enum { IDD = IDD_ABOUTBOX };
  16. protected:
  17. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
  18. // 实现
  19. protected:
  20. DECLARE_MESSAGE_MAP()
  21. };
  22. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  23. {
  24. }
  25. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  26. {
  27. CDialog::DoDataExchange(pDX);
  28. }
  29. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  30. END_MESSAGE_MAP()
  31. // CPlayerDlg 对话框
  32. CPlayerDlg::CPlayerDlg(CWnd* pParent /*=NULL*/)
  33. : CDialog(CPlayerDlg::IDD, pParent)
  34. {
  35. m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON2);
  36. }
  37. void CPlayerDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CDialog::DoDataExchange(pDX);
  40. DDX_Control(pDX, IDC_ACTIVEMOVIECONTROL1, m_amovie);
  41. }
  42. BEGIN_MESSAGE_MAP(CPlayerDlg, CDialog)
  43. ON_WM_SYSCOMMAND()
  44. ON_WM_PAINT()
  45. ON_WM_QUERYDRAGICON()
  46. //}}AFX_MSG_MAP
  47. // ON_BN_CLICKED(IDC_OPEN, &CPlayerDlg::OnBnClickedOpen)
  48. // ON_BN_CLICKED(IDC_START, &CPlayerDlg::OnBnClickedStart)
  49. ON_COMMAND(ID_PLAYSTOP, OnPlaystop)
  50. ON_COMMAND(ID_OPEN,OnOpen)
  51. ON_COMMAND(ID_PLAY,OnPlay)
  52. ON_COMMAND(ID_PAUSE,OnPause)
  53. ON_COMMAND(ID_EXIT,OnExit)
  54. ON_COMMAND(ID_CLOSE,OnClose)
  55. ON_COMMAND(ID_VEDIOFULL,OnVedioFull)
  56. ON_COMMAND(ID_VEDIO1,OnVedio1)
  57. ON_COMMAND(ID_CCTV1,OnCctv1)
  58. END_MESSAGE_MAP()
  59. // CPlayerDlg 消息处理程序
  60. BOOL CPlayerDlg::OnInitDialog()
  61. {
  62. CDialog::OnInitDialog();
  63. // 将“关于...”菜单项添加到系统菜单中。
  64. // IDM_ABOUTBOX 必须在系统命令范围内。
  65. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  66. ASSERT(IDM_ABOUTBOX < 0xF000);
  67. CMenu* pSysMenu = GetSystemMenu(FALSE);
  68. if (pSysMenu != NULL)
  69. {
  70. CString strAboutMenu;
  71. strAboutMenu.LoadString(IDS_ABOUTBOX);
  72. if (!strAboutMenu.IsEmpty())
  73. {
  74. pSysMenu->AppendMenu(MF_SEPARATOR);
  75. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  76. }
  77. }
  78. //把菜单加进对话框里面
  79. /*CMenu  MyMenu3; 
  80.     MyMenu3.LoadMenu(IDR_MENU);//IDR_MENU是菜单的资源ID。 
  81.     this->SetMenu(&MyMenu3); 
  82.     MyMenu3.Detach(); */
  83. // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
  84. //  执行此操作
  85. SetIcon(m_hIcon, TRUE); // 设置大图标
  86. SetIcon(m_hIcon, FALSE); // 设置小图标
  87. // TODO: 在此添加额外的初始化代码
  88. return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
  89. }
  90. void CPlayerDlg::OnSysCommand(UINT nID, LPARAM lParam)
  91. {
  92. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  93. {
  94. CAboutDlg dlgAbout;
  95. dlgAbout.DoModal();
  96. }
  97. else
  98. {
  99. CDialog::OnSysCommand(nID, lParam);
  100. }
  101. }
  102. // 如果向对话框添加最小化按钮,则需要下面的代码
  103. //  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
  104. //  这将由框架自动完成。
  105. void CPlayerDlg::OnPaint()
  106. {
  107. if (IsIconic())
  108. {
  109. CPaintDC dc(this); // 用于绘制的设备上下文
  110. SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  111. // 使图标在工作区矩形中居中
  112. int cxIcon = GetSystemMetrics(SM_CXICON);
  113. int cyIcon = GetSystemMetrics(SM_CYICON);
  114. CRect rect;
  115. GetClientRect(&rect);
  116. int x = (rect.Width() - cxIcon + 1) / 2;
  117. int y = (rect.Height() - cyIcon + 1) / 2;
  118. // 绘制图标
  119. dc.DrawIcon(x, y, m_hIcon);
  120. }
  121. else//添加背景图图片代码:
  122. {
  123. CDialog::OnPaint();//禁止这个调用   
  124. /*CPaintDC  dc(this);   
  125.     CRect  rect;   
  126. GetClientRect(&rect);   
  127. CDC  dcMem;   
  128. dcMem.CreateCompatibleDC(&dc);   
  129. CBitmap  bmpBackground;   
  130. bmpBackground.LoadBitmap(IDC_ACTIVEMOVIECONTROL1);  
  131. //IDB_BITMAP是你自己的图对应的ID
  132. BITMAP  bitmap;   
  133. bmpBackground.GetBitmap(&bitmap);   
  134. CBitmap  *pbmpOld=dcMem.SelectObject(&bmpBackground);
  135. dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);  */ 
  136. }
  137. }
  138. //当用户拖动最小化窗口时系统调用此函数取得光标
  139. //显示。
  140. HCURSOR CPlayerDlg::OnQueryDragIcon()
  141. {
  142. return static_cast<HCURSOR>(m_hIcon);
  143. }
  144. void CPlayerDlg::OnOpen()
  145. {
  146. CFileDialog dlg(TRUE,NULL,NULL,0,"所有文件|*.*",NULL);
  147. if(dlg.DoModal()==IDOK)
  148. {
  149. m_amovie.SetFileName(dlg.GetPathName());
  150. }
  151. // TODO: 在此添加控件通知处理程序代码
  152. }
  153. void CPlayerDlg::OnPlay()
  154. {
  155. m_amovie.Run();
  156. }
  157. void CPlayerDlg::OnPause()
  158. {
  159. m_amovie.Pause();
  160. }
  161. void CPlayerDlg::OnPlaystop()
  162. {
  163. m_amovie.Stop();
  164. }
  165. void CPlayerDlg::OnClose()
  166. {
  167. m_amovie.SetFileName("");
  168. }
  169. void CPlayerDlg::OnExit()
  170. {
  171. OnCancel();
  172. }
  173. void CPlayerDlg::MoveMovieWindow()
  174. {
  175. //改变窗口大小以适应控件大小
  176. /*CRect rc1,rc2,rc3,rect;
  177. int woc;
  178. //得到ActiveMovie控件大小
  179. GetWindowRect( &rect );
  180. if(m_amovie.GetSafeHwnd())
  181. {
  182. m_amovie.MoveWindow(CRect(0,22,rect.Width(),rect.Height()-20),TRUE);
  183. }
  184. //HWND  hwndChild=::GetWindow((HWND)IDC_ACTIVEMOVIECONTROL1,GW_CHILD);  
  185. //woc=::GetDlgCtrlID(hwndChild);//取得ID
  186. /*m_amovie.GetWindowRect(&rc1);
  187. //保证对话框客户区的宽不小于300象素,高不小于225象素
  188. if(rc1.Width()<300||rc1.Height()<255)
  189. {
  190. rc1.right=rc1.left+300;
  191. rc1.bottom=rc1.top+225;
  192. }
  193. //获得对话框的大小
  194. GetWindowRect(&rc2);
  195. //获得对话框客户区大小
  196.     GetClientRect(&rc3);
  197. //改变对话框大小以适应ActiveMovie控件大小
  198. MoveWindow(rc2.left,rc2.top,rc2.Width()-rc3.Width()+rc1.Width(),
  199. rc2.Height()-rc3.Height()+rc1.Height());
  200. //获得控件ActiveMovie的大小
  201. m_amovie.GetWindowRect(&rc1);
  202. GetClientRect(&rc3);
  203. //使ActiveMovie控件在对话框的客户区居中
  204. m_amovie.MoveWindow((rc3.Width()-rc1.Width())/2,
  205. (rc3.Height()-rc1.Height())/2,rc1.Width(),rc1.Height());*/
  206. }
  207. BEGIN_EVENTSINK_MAP(CPlayerDlg, CDialog)
  208.     //{{AFX_EVENTSINK_MAP(CPlayerDlg)
  209. //}}AFX_EVENTSINK_MAP
  210. ON_EVENT(CPlayerDlg, IDC_ACTIVEMOVIECONTROL1, 1, CPlayerDlg::StateChangeActivemoviecontrol1, VTS_I4 VTS_I4)
  211. //ON_EVENT(CPlayerDlg, IDC_ACTIVEMOVIECONTROL1, DISPID_READYSTATECHANGE, CPlayerDlg::ReadyStateChangeActivemoviecontrol1, VTS_I4)
  212. ON_EVENT(CPlayerDlg, IDC_ACTIVEMOVIECONTROL1, 51, CPlayerDlg::DisplayModeChangeActivemoviecontrol1, VTS_NONE)
  213. ON_EVENT(CPlayerDlg, IDC_ACTIVEMOVIECONTROL1, 999, CPlayerDlg::ErrorActivemoviecontrol1, VTS_I2 VTS_BSTR VTS_BSTR VTS_PBOOL)
  214. ON_EVENT(CPlayerDlg, IDC_ACTIVEMOVIECONTROL1, 50, CPlayerDlg::OpenCompleteActivemoviecontrol1, VTS_NONE)
  215. END_EVENTSINK_MAP()
  216. void CPlayerDlg::OnVedio1()//视频的2倍
  217. {
  218. m_amovie.Pause();
  219. m_amovie.SetMovieWindowSize(1);
  220. m_amovie.Run(); 
  221. }
  222. void CPlayerDlg::OnVedioFull()//全屏
  223. {
  224. m_amovie.Pause();
  225. m_amovie.SetFullScreenMode(TRUE);
  226. m_amovie.Run();
  227. }
  228. // This OnCtlColor handler will change the color of a static control
  229. // with the ID of IDC_MYSTATIC. The code assumes that the CPenWidthsDlg
  230. // class has an initialized and created CBrush member named m_brush.
  231. // The control will be painted with red text and a background
  232. // color of m_brush.
  233. HBRUSH CPlayerDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  234. {
  235.    // Call the base class implementation first! Otherwise, it may
  236.    // undo what we're trying to accomplish here.
  237.    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  238.    // Are we painting the IDC_MYSTATIC control? We can use
  239.    // CWnd::GetDlgCtrlID() to perform the most efficient test.
  240.    if (pWnd->GetDlgCtrlID() == IDC_ACTIVEMOVIECONTROL1)
  241.    {
  242.       // Set the text color to red
  243.       pDC->SetTextColor(RGB(255, 0, 0));
  244.       // Set the background mode for text to transparent 
  245.       // so background will show thru.
  246.       pDC->SetBkMode(TRANSPARENT);
  247.       // Return handle to our CBrush object
  248.       hbr = m_brush;
  249.    }
  250.    return hbr;
  251. }
  252. void CPlayerDlg::OnDestroy()
  253. {
  254.           CDialog::OnDestroy();
  255.           // Free the space allocated for the background brush
  256.           delete m_pEditBkBrush;
  257. }
  258. void CPlayerDlg::StateChangeActivemoviecontrol1(long oldState, long newState)
  259. {
  260. MoveMovieWindow();
  261. // TODO: 在此处添加消息处理程序代码
  262. }
  263. void CPlayerDlg::ReadyStateChangeActivemoviecontrol1(long ReadyState)
  264. {
  265. MoveMovieWindow();
  266. // TODO: 在此处添加消息处理程序代码
  267. }
  268. void CPlayerDlg::DisplayModeChangeActivemoviecontrol1()
  269. {
  270. MoveMovieWindow();
  271. // TODO: 在此处添加消息处理程序代码
  272. }
  273. void CPlayerDlg::ErrorActivemoviecontrol1(short SCode, LPCTSTR Description, LPCTSTR Source, BOOL* CancelDisplay)
  274. {
  275. CString str;
  276. str.Format("出现错误[%d]:nn%s",SCode,Description);
  277. MessageBox(str);
  278. *CancelDisplay=TRUE;
  279. // TODO: 在此处添加消息处理程序代码
  280. }
  281. void CPlayerDlg::OpenCompleteActivemoviecontrol1()
  282. {
  283. m_amovie.Run();
  284. // TODO: 在此处添加消息处理程序代码
  285. }
  286. void CPlayerDlg::OnCctv1()
  287. {
  288. m_amovie.SetFileName("mms://218.19.175.167:1755/stv4 ");
  289. }