RmPlayerDlg.cpp
上传用户:sdpcwz
上传日期:2009-12-14
资源大小:1237k
文件大小:5k
源码类别:

书籍源码

开发平台:

Visual C++

  1. // RmPlayerDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "RmPlayer.h"
  5. #include "RmPlayerDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CAboutDlg dialog used for App About
  13. class CAboutDlg : public CDialog
  14. {
  15. public:
  16. CAboutDlg();
  17. // Dialog Data
  18. //{{AFX_DATA(CAboutDlg)
  19. enum { IDD = IDD_ABOUTBOX };
  20. //}}AFX_DATA
  21. // ClassWizard generated virtual function overrides
  22. //{{AFX_VIRTUAL(CAboutDlg)
  23. protected:
  24. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  25. //}}AFX_VIRTUAL
  26. // Implementation
  27. protected:
  28. //{{AFX_MSG(CAboutDlg)
  29. //}}AFX_MSG
  30. DECLARE_MESSAGE_MAP()
  31. };
  32. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  33. {
  34. //{{AFX_DATA_INIT(CAboutDlg)
  35. //}}AFX_DATA_INIT
  36. }
  37. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CDialog::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CAboutDlg)
  41. //}}AFX_DATA_MAP
  42. }
  43. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  44. //{{AFX_MSG_MAP(CAboutDlg)
  45. // No message handlers
  46. //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CRmPlayerDlg dialog
  50. CRmPlayerDlg::CRmPlayerDlg(CWnd* pParent /*=NULL*/)
  51. : CDialog(CRmPlayerDlg::IDD, pParent)
  52. {
  53. //{{AFX_DATA_INIT(CRmPlayerDlg)
  54. // NOTE: the ClassWizard will add member initialization here
  55. //}}AFX_DATA_INIT
  56. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  57. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  58. }
  59. void CRmPlayerDlg::DoDataExchange(CDataExchange* pDX)
  60. {
  61. CDialog::DoDataExchange(pDX);
  62. //{{AFX_DATA_MAP(CRmPlayerDlg)
  63. // NOTE: the ClassWizard will add DDX and DDV calls here
  64. //}}AFX_DATA_MAP
  65. }
  66. BEGIN_MESSAGE_MAP(CRmPlayerDlg, CDialog)
  67. //{{AFX_MSG_MAP(CRmPlayerDlg)
  68. ON_WM_SYSCOMMAND()
  69. ON_WM_PAINT()
  70. ON_WM_QUERYDRAGICON()
  71. ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
  72. ON_COMMAND(ID_FILE_EXIT, OnFileExit)
  73. ON_COMMAND(ID_VIEW_FULLSCREEN, OnViewFullscreen)
  74. ON_COMMAND(ID_VIEW_ORIGINAL, OnViewOriginal)
  75. //}}AFX_MSG_MAP
  76. END_MESSAGE_MAP()
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CRmPlayerDlg message handlers
  79. BOOL CRmPlayerDlg::OnInitDialog()
  80. {
  81. CDialog::OnInitDialog();
  82. // Add "About..." menu item to system menu.
  83. // IDM_ABOUTBOX must be in the system command range.
  84. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  85. ASSERT(IDM_ABOUTBOX < 0xF000);
  86. CMenu* pSysMenu = GetSystemMenu(FALSE);
  87. if (pSysMenu != NULL)
  88. {
  89. CString strAboutMenu;
  90. strAboutMenu.LoadString(IDS_ABOUTBOX);
  91. if (!strAboutMenu.IsEmpty())
  92. {
  93. pSysMenu->AppendMenu(MF_SEPARATOR);
  94. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  95. }
  96. }
  97. // Set the icon for this dialog.  The framework does this automatically
  98. //  when the application's main window is not a dialog
  99. SetIcon(m_hIcon, TRUE); // Set big icon
  100. SetIcon(m_hIcon, FALSE); // Set small icon
  101. //创建播放器
  102. CRect rc;
  103. GetClientRect(&rc);
  104. m_Player.Create("Rm Player",WS_CHILD|WS_MAXIMIZE|WS_BORDER|WS_DLGFRAME,rc,this,IDC_PLAYER,NULL,FALSE);
  105. //设置播放器允许全屏和还原原始尺寸
  106. m_Player.SetEnableFullScreen(TRUE);
  107. m_Player.SetEnableOriginalSize(TRUE);
  108. //设置播放器显示视频窗口,控制条状态
  109. CString str = "IMAGEWINDOW,CONTROLPANEL,STATUSBAR";
  110. m_Player.SetControls(str);
  111. return TRUE;  // return TRUE  unless you set the focus to a control
  112. }
  113. void CRmPlayerDlg::OnSysCommand(UINT nID, LPARAM lParam)
  114. {
  115. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  116. {
  117. CAboutDlg dlgAbout;
  118. dlgAbout.DoModal();
  119. }
  120. else
  121. {
  122. CDialog::OnSysCommand(nID, lParam);
  123. }
  124. }
  125. // If you add a minimize button to your dialog, you will need the code below
  126. //  to draw the icon.  For MFC applications using the document/view model,
  127. //  this is automatically done for you by the framework.
  128. void CRmPlayerDlg::OnPaint() 
  129. {
  130. if (IsIconic())
  131. {
  132. CPaintDC dc(this); // device context for painting
  133. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  134. // Center icon in client rectangle
  135. int cxIcon = GetSystemMetrics(SM_CXICON);
  136. int cyIcon = GetSystemMetrics(SM_CYICON);
  137. CRect rect;
  138. GetClientRect(&rect);
  139. int x = (rect.Width() - cxIcon + 1) / 2;
  140. int y = (rect.Height() - cyIcon + 1) / 2;
  141. // Draw the icon
  142. dc.DrawIcon(x, y, m_hIcon);
  143. }
  144. else
  145. {
  146. CDialog::OnPaint();
  147. }
  148. }
  149. // The system calls this to obtain the cursor to display while the user drags
  150. //  the minimized window.
  151. HCURSOR CRmPlayerDlg::OnQueryDragIcon()
  152. {
  153. return (HCURSOR) m_hIcon;
  154. }
  155. void CRmPlayerDlg::OnFileOpen() 
  156. {
  157. //设置过滤字符串
  158. CString strFilter = "RealMedia Files(*.rm)|*.rm|MP3 Files(*.mp3)|*.mp3|All Files(*.*)|*.*||";
  159. //构造打开对话框对象
  160. CFileDialog fileDlg(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT,strFilter,this);
  161. if(fileDlg.DoModal()==IDOK)
  162. {
  163. //设置播放文件
  164. m_Player.SetSource(fileDlg.GetPathName());
  165. //开始播放
  166. m_Player.DoPlay();
  167. }
  168. }
  169. //退出
  170. void CRmPlayerDlg::OnFileExit() 
  171. {
  172. CDialog::OnOK();
  173. }
  174. //全屏
  175. void CRmPlayerDlg::OnViewFullscreen() 
  176. {
  177. m_Player.SetFullScreen();
  178. }
  179. //还原原始尺寸
  180. void CRmPlayerDlg::OnViewOriginal() 
  181. {
  182. m_Player.SetOriginalSize();
  183. }