CientDlg.cpp
上传用户:weiliangfb
上传日期:2007-01-23
资源大小:142k
文件大小:7k
源码类别:

多媒体

开发平台:

Visual C++

  1. // CientDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Cient.h"
  5. #include "CientDlg.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. // CCientDlg dialog
  50. CCientDlg::CCientDlg(CWnd* pParent /*=NULL*/)
  51. : CDialog(CCientDlg::IDD, pParent)
  52. {
  53. //{{AFX_DATA_INIT(CCientDlg)
  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. m_pDPClient = new CDPClient(this);
  59. m_WaiteHaveExit.SetEvent();
  60. m_llDataPos = 0;
  61. m_dwSize = 0;
  62. m_MedialpBuffer = new BYTE[1024*1024*2];
  63. }
  64. void CCientDlg::DoDataExchange(CDataExchange* pDX)
  65. {
  66. CDialog::DoDataExchange(pDX);
  67. //{{AFX_DATA_MAP(CCientDlg)
  68. // NOTE: the ClassWizard will add DDX and DDV calls here
  69. //}}AFX_DATA_MAP
  70. }
  71. BEGIN_MESSAGE_MAP(CCientDlg, CDialog)
  72. //{{AFX_MSG_MAP(CCientDlg)
  73. ON_WM_SYSCOMMAND()
  74. ON_WM_PAINT()
  75. ON_WM_QUERYDRAGICON()
  76. ON_WM_DESTROY()
  77. ON_BN_CLICKED(IDC_BTN_START, OnBtnStart)
  78. ON_BN_CLICKED(IDC_BTN_PLAY, OnBtnPlay)
  79. ON_BN_CLICKED(IDC_BTN_PAUSE, OnBtnPause)
  80. ON_BN_CLICKED(IDC_BTN_SETRAT, OnBtnSetrat)
  81. //}}AFX_MSG_MAP
  82. END_MESSAGE_MAP()
  83. /////////////////////////////////////////////////////////////////////////////
  84. // CCientDlg message handlers
  85. BOOL CCientDlg::OnInitDialog()
  86. {
  87. CDialog::OnInitDialog();
  88. // Add "About..." menu item to system menu.
  89. // IDM_ABOUTBOX must be in the system command range.
  90. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  91. ASSERT(IDM_ABOUTBOX < 0xF000);
  92. CMenu* pSysMenu = GetSystemMenu(FALSE);
  93. if (pSysMenu != NULL)
  94. {
  95. CString strAboutMenu;
  96. strAboutMenu.LoadString(IDS_ABOUTBOX);
  97. if (!strAboutMenu.IsEmpty())
  98. {
  99. pSysMenu->AppendMenu(MF_SEPARATOR);
  100. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  101. }
  102. }
  103. // Set the icon for this dialog.  The framework does this automatically
  104. //  when the application's main window is not a dialog
  105. SetIcon(m_hIcon, TRUE); // Set big icon
  106. SetIcon(m_hIcon, FALSE); // Set small icon
  107. // TODO: Add extra initialization here
  108. m_pDPClient->InitNetEnvironment();
  109. return TRUE;  // return TRUE  unless you set the focus to a control
  110. }
  111. void CCientDlg::OnSysCommand(UINT nID, LPARAM lParam)
  112. {
  113. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  114. {
  115. CAboutDlg dlgAbout;
  116. dlgAbout.DoModal();
  117. }
  118. else
  119. {
  120. CDialog::OnSysCommand(nID, lParam);
  121. }
  122. }
  123. // If you add a minimize button to your dialog, you will need the code below
  124. //  to draw the icon.  For MFC applications using the document/view model,
  125. //  this is automatically done for you by the framework.
  126. void CCientDlg::OnPaint() 
  127. {
  128. if (IsIconic())
  129. {
  130. CPaintDC dc(this); // device context for painting
  131. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  132. // Center icon in client rectangle
  133. int cxIcon = GetSystemMetrics(SM_CXICON);
  134. int cyIcon = GetSystemMetrics(SM_CYICON);
  135. CRect rect;
  136. GetClientRect(&rect);
  137. int x = (rect.Width() - cxIcon + 1) / 2;
  138. int y = (rect.Height() - cyIcon + 1) / 2;
  139. // Draw the icon
  140. dc.DrawIcon(x, y, m_hIcon);
  141. }
  142. else
  143. {
  144. CDialog::OnPaint();
  145. }
  146. }
  147. // The system calls this to obtain the cursor to display while the user drags
  148. //  the minimized window.
  149. HCURSOR CCientDlg::OnQueryDragIcon()
  150. {
  151. return (HCURSOR) m_hIcon;
  152. }
  153. void CCientDlg::OnDestroy() 
  154. {
  155. CDialog::OnDestroy();
  156. // TODO: Add your message handler code here
  157. m_Exit.SetEvent();
  158. m_WaiteHaveExit.Lock();
  159. delete m_pDPClient;
  160. delete []m_MedialpBuffer;
  161. }
  162. HRESULT  CCientDlg::OnDataArrive(LONGLONG llDataPos,DWORD dwSize,LPBYTE lpBuffer)
  163. {
  164. CopyMemory(m_MedialpBuffer,lpBuffer,dwSize);
  165. m_llDataPos = llDataPos;
  166. m_dwSize = dwSize;
  167. m_EventDataArrive.SetEvent();
  168. return S_OK;
  169. }
  170. HRESULT  CCientDlg::OnLenghtArrive(LONGLONG lMediaLen)
  171. {
  172. m_llMediaLen = lMediaLen;
  173. GetDlgItem(IDC_BTN_PLAY)->EnableWindow(TRUE);
  174. GetDlgItem(IDC_BTN_PAUSE)->EnableWindow(TRUE);
  175. return S_OK;
  176. }
  177. void CCientDlg::OnBtnStart() 
  178. {
  179. // TODO: Add your control notification handler code here
  180. HRESULT hr = m_pDPClient->ConnectDirectly();
  181. if(FAILED(hr))
  182. return ;
  183. GetDlgItem(IDC_BTN_START)->EnableWindow(FALSE);
  184. m_pDPClient->SendMediaLenRequire();
  185. }
  186. HRESULT CCientDlg::OnPlayerNeedData(LONGLONG llDataPos,DWORD dwSize,DWORD * pdwGotSize,LPBYTE lpBuffer)
  187. {
  188. m_WaiteHaveExit.ResetEvent();
  189. m_pDPClient->SendMediaDataRequire(llDataPos,dwSize);
  190. CSyncObject* Objects[2] = {&m_EventDataArrive,&m_Exit};
  191. CMultiLock Lock(Objects,2);
  192. while(1)
  193. {
  194. DWORD obj = Lock.Lock(3000,FALSE);
  195. if(obj==WAIT_OBJECT_0)
  196. {
  197. if(m_llDataPos==llDataPos&&dwSize==m_dwSize)
  198. break;
  199. }
  200. else if(obj==WAIT_OBJECT_0+1)
  201. {
  202. m_WaiteHaveExit.SetEvent();
  203. return E_FAIL;
  204. }
  205. //else //time out
  206. // {
  207. // }
  208. m_pDPClient->SendMediaDataRequire(llDataPos,dwSize);
  209. }
  210. CopyMemory(lpBuffer,m_MedialpBuffer,dwSize);
  211.  *pdwGotSize = dwSize;
  212. m_WaiteHaveExit.SetEvent();
  213. return S_OK;
  214. }
  215. void CCientDlg::OnBtnPlay() 
  216. {
  217. // TODO: Add your control notification handler code here
  218. if(m_Player.InitPlayer(m_llMediaLen,this,::GetDlgItem(m_hWnd,IDC_VIDEO)))
  219. m_Player.Run();
  220. GetDlgItem(IDC_BTN_SETRAT)->EnableWindow(TRUE);
  221. }
  222. void CCientDlg::OnBtnPause() 
  223. {
  224. // TODO: Add your control notification handler code here
  225. if(m_Player.InitPlayer(m_llMediaLen,this,::GetDlgItem(m_hWnd,IDC_VIDEO)))
  226. m_Player.Pause();
  227. }
  228. void CCientDlg::OnBtnSetrat() 
  229. {
  230. // TODO: Add your control notification handler code here
  231. UINT Fps = GetDlgItemInt(IDC_ED_FPS);
  232. m_Player.SetPlayRate((double)Fps);
  233. }