PIDTestDlg.cpp
上传用户:hxb_1234
上传日期:2010-03-30
资源大小:8328k
文件大小:4k
源码类别:

VC书籍

开发平台:

Visual C++

  1. // PIDTestDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include <streams.h>
  5. #include "CDXGraph.h"
  6. #include "IMPEG1Builder.h"
  7. #include <initguid.h>
  8. #include "FltGuids.h"
  9. #include "PIDTest.h"
  10. #include "PIDTestDlg.h"
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CPIDTestDlg dialog
  18. CPIDTestDlg::CPIDTestDlg(CWnd* pParent /*=NULL*/)
  19. : CDialog(CPIDTestDlg::IDD, pParent)
  20. {
  21. //{{AFX_DATA_INIT(CPIDTestDlg)
  22. // NOTE: the ClassWizard will add member initialization here
  23. //}}AFX_DATA_INIT
  24. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  25. m_hIcon  = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  26. m_pGraph = NULL;
  27. }
  28. CPIDTestDlg::~CPIDTestDlg()
  29. {
  30. if (m_pGraph)
  31. {
  32. delete m_pGraph;
  33. m_pGraph = NULL;
  34. }
  35. }
  36. void CPIDTestDlg::DoDataExchange(CDataExchange* pDX)
  37. {
  38. CDialog::DoDataExchange(pDX);
  39. //{{AFX_DATA_MAP(CPIDTestDlg)
  40. // NOTE: the ClassWizard will add DDX and DDV calls here
  41. //}}AFX_DATA_MAP
  42. }
  43. BEGIN_MESSAGE_MAP(CPIDTestDlg, CDialog)
  44. //{{AFX_MSG_MAP(CPIDTestDlg)
  45. ON_WM_PAINT()
  46. ON_WM_QUERYDRAGICON()
  47. ON_BN_CLICKED(ID_CMD_PAUSE, OnCmdPause)
  48. ON_BN_CLICKED(ID_CMD_PLAY, OnCmdPlay)
  49. ON_BN_CLICKED(ID_CMD_STOP, OnCmdStop)
  50. ON_BN_CLICKED(ID_CMD_OPEN, OnCmdOpen)
  51. //}}AFX_MSG_MAP
  52. END_MESSAGE_MAP()
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CPIDTestDlg message handlers
  55. BOOL CPIDTestDlg::OnInitDialog()
  56. {
  57. CDialog::OnInitDialog();
  58. // Set the icon for this dialog.  The framework does this automatically
  59. //  when the application's main window is not a dialog
  60. SetIcon(m_hIcon, TRUE); // Set big icon
  61. SetIcon(m_hIcon, FALSE); // Set small icon
  62. // TODO: Add extra initialization here
  63. SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
  64. return TRUE;  // return TRUE  unless you set the focus to a control
  65. }
  66. // If you add a minimize button to your dialog, you will need the code below
  67. //  to draw the icon.  For MFC applications using the document/view model,
  68. //  this is automatically done for you by the framework.
  69. void CPIDTestDlg::OnPaint() 
  70. {
  71. if (IsIconic())
  72. {
  73. CPaintDC dc(this); // device context for painting
  74. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  75. // Center icon in client rectangle
  76. int cxIcon = GetSystemMetrics(SM_CXICON);
  77. int cyIcon = GetSystemMetrics(SM_CYICON);
  78. CRect rect;
  79. GetClientRect(&rect);
  80. int x = (rect.Width() - cxIcon + 1) / 2;
  81. int y = (rect.Height() - cyIcon + 1) / 2;
  82. // Draw the icon
  83. dc.DrawIcon(x, y, m_hIcon);
  84. }
  85. else
  86. {
  87. CDialog::OnPaint();
  88. }
  89. }
  90. // The system calls this to obtain the cursor to display while the user drags
  91. //  the minimized window.
  92. HCURSOR CPIDTestDlg::OnQueryDragIcon()
  93. {
  94. return (HCURSOR) m_hIcon;
  95. }
  96. void CPIDTestDlg::OnCmdOpen() 
  97. {
  98. CString      strFilter = "MPEG File (*.mpg;*.mpeg)|*.mpg;*.mpeg|";
  99. CFileDialog  dlgOpen(TRUE, NULL, NULL, OFN_HIDEREADONLY, strFilter, NULL);
  100. if (IDOK != dlgOpen.DoModal()) 
  101. {
  102. return;
  103. }
  104. mSourceFile = dlgOpen.GetPathName();
  105. // Rebuild the filter graph
  106. if (m_pGraph)
  107. {
  108. m_pGraph->Stop();
  109. delete m_pGraph;
  110. m_pGraph = NULL;
  111. }
  112. m_pGraph = new CDXGraph();
  113. m_pGraph->Create();
  114. IMPEG1Builder * pMPG1Builder = NULL;
  115. m_pGraph->QueryInterface(IID_IMPEG1Builder, (void**)&pMPG1Builder);
  116. if (pMPG1Builder)
  117. {
  118. pMPG1Builder->Release();
  119. if (S_OK == pMPG1Builder->IsMPEG1File(mSourceFile))
  120. {
  121. pMPG1Builder->RenderMPEG1File(mSourceFile);
  122. // Automatically play this MPEG1 file
  123. OnCmdPlay();
  124. }
  125. else
  126. {
  127. AfxMessageBox("This is not a MPEG1 file!");
  128. }
  129. }
  130. }
  131. void CPIDTestDlg::OnCmdPause() 
  132. {
  133. if (m_pGraph)
  134. {
  135. m_pGraph->Pause();
  136. }
  137. }
  138. void CPIDTestDlg::OnCmdPlay() 
  139. {
  140. if (m_pGraph)
  141. {
  142. m_pGraph->Run();
  143. }
  144. }
  145. void CPIDTestDlg::OnCmdStop() 
  146. {
  147. if (m_pGraph)
  148. {
  149. m_pGraph->Stop();
  150. }
  151. }