//==========================================================================;
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
// PURPOSE.
//
// Copyright (c) 1994 - 1998 Microsoft Corporation. All Rights Reserved.
//
//--------------------------------------------------------------------------;
//
// MovieView.cpp : implementation of the CMovieView class
// aze
// (c) Stephane Rodriguez 98
#include "stdafx.h"
#include "MovieApp.h"
#include "MovieDoc.h"
#include <mmstream.h> // Multimedia stream interfaces
#include <mmreg.h>
#include <amstream.h> // DirectShow multimedia stream interfaces
#include <initguid.h> // Defines DEFINE_GUID macro and enables GUID initialization
#include "MovieView.h"
#include <atlbase.h>
CComModule _Module;
#include <atlcom.h>
#include <atlimpl.cpp>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMovieView
IMPLEMENT_DYNCREATE(CMovieView, CView)
BEGIN_MESSAGE_MAP(CMovieView, CView)
//{{AFX_MSG_MAP(CMovieView)
// NOTE - the ClassWizard will add and remove mapping macros here.
ON_WM_KEYDOWN()
ON_WM_LBUTTONDOWN()
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(IDM_START, OnStart)
ON_COMMAND(IDM_PAUSE, OnPause)
ON_COMMAND(IDM_STOP, OnStop)
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMovieView construction/destruction
CMovieView::CMovieView()
{
m_bAppactive=FALSE;
m_bFileLoaded = FALSE;
m_bPaused=FALSE;
// MultiMedia streaming interfaces
m_pMMStream=NULL;
m_pPrimaryVidStream=NULL;
m_pDDStream=NULL;
m_pSample=NULL;
//DirectDrawEx interfaces
m_pDD=NULL;
m_pDD3=NULL;
m_pDDF=NULL;
m_pPrimarySurface=NULL;
m_pDDSOffscreen=NULL;
m_pDDSOffscreen2=NULL;
m_pDDClipper=NULL;
// attach the view to the app (to easier interfacing)
((CMovieApp*)AfxGetApp())->OnViewChildCreated(this);
}
CMovieView::~CMovieView()
{
ExitCode();
}
BOOL CMovieView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMovieView drawing
void CMovieView::OnDraw(CDC* pDC)
{
CMovieDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// draw a black background when the video is not yet loaded
// so we are dealing with a video application and not a simple
// MFC MDI type.
if (!m_bFileLoaded)
{
CBrush brush;
brush.CreateSolidBrush(RGB(0,0,0));
CRect rect;
GetClientRect(&rect);
pDC->FillRect(&rect,&brush);
}
}
BOOL CMovieView::OnEraseBkgnd( CDC* pDC )
{
return TRUE;
}
HRESULT CMovieView::InitDDrawEx()
{
HRESULT hr=NOERROR;
DDSURFACEDESC ddsd, ddsd2, ddsd3;
CoInitialize(NULL);
//Create a DirectDrawFactory object
hr = CoCreateInstance(
CLSID_DirectDrawFactory, NULL, CLSCTX_INPROC_SERVER,
IID_IDirectDrawFactory, (void **)&m_pDDF);
if (FAILED(hr))
{
AfxMessageBox(_T("Couldn't create DirectDrawFactory"));
return E_FAIL;
}
//Call the IDirectDrawFactory::CreateDirectDraw method to create the
//DirectDraw object, set the cooperative level, and get the address
//of an IDirectDraw interface pointer
hr = (m_pDDF->CreateDirectDraw(NULL, ::GetDesktopWindow(), DDSCL_NORMAL,
NULL, NULL, &m_pDD));
if (FAILED(hr))
{
AfxMessageBox(_T("Couldn't create DirectDraw object"));
return E_FAIL;
}
//Now query for the new IDirectDraw3 interface
hr =(m_pDD->QueryInterface(IID_IDirectDraw3, (LPVOID*)&m_pDD3));
if (FAILED(hr))
{
AfxMessageBox(_T("Couldn't get IDirectDraw3"));
return E_FAIL;
}
//Initialize the DDSURFACEDESC structure for the primary surface
::ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
hr = m_pDD3->CreateSurface(&ddsd, &m_pPrimarySurface, NULL);
if(FAILED(hr))
{
AfxMessageBox(_T("Couldn't create Primary Surface"));
return E_FAIL;
}
// Now, do the same for the offscreen surfaces.
// The offscreen surface needs to use the same pixel format as the primary.
// Query the primary surface to for its pixel format.
hr = m_pPrimarySurface->GetSurfaceDesc(&ddsd);
if(FAILED(hr))
{
AfxMessageBox(_T("Couldn't GetSurfaceDesc"));
return E_FAIL;
}
// Now, set the info for the offscreen surface #1, using the primary's pixel format.
::ZeroMemory(&ddsd2, sizeof(ddsd2));
ddsd2.dwSize = sizeof(ddsd2);
ddsd2.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd2.dwHeight = ddsd.dwHeight; //set the height of the surfaces equal
ddsd2.dwWidth = ddsd.dwWidth; //set the width of the surfaces equal
ddsd2.ddpfPixelFormat = ddsd.ddpfPixelFormat; //set the pixel formats equal
// Now, create the offscreen surface #1 and query for the latest interface.
hr = m_pDD3->CreateSurface(&ddsd2, &m_pDDSOffscreen, NULL);
if(FAILED(hr))
{
AfxMessageBox(_T("Couldn't create Offscreen Surface"));
return E_FAIL;
}
// Now, set the info for the offscreen surface #2, using the primary's pixel format.
::ZeroMemory(&ddsd3, sizeof(ddsd3));
ddsd3.dwSize = sizeof(ddsd3);
ddsd3.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
ddsd3.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd3.dwHeight = ddsd.dwHeight; //set the height of the surfaces equal
ddsd3.dwWidth = ddsd.dwWidth; //set the width of the surfaces equal
ddsd3.ddpfPixelFormat = ddsd.ddpfPixelFormat; //set the pixel formats equal
// Now, create the offscreen surface #2 and query for the latest interface.
hr = m_pDD3->CreateSurface(&ddsd3, &m_pDDSOffscreen2, NULL);
if(FAILED(hr))
{
AfxMessageBox(_T("Couldn't create Offscreen Surface2"));
return E_FAIL;
}
//Add code for Clipper
hr = m_pDD3->CreateClipper(0, &m_pDDClipper, NULL);
if(FAILED(hr))
{
AfxMessageBox(_T("Couldn't create Clipper"));
return E_FAIL;
}
hr = m_pPrimarySurface->SetClipper(m_pDDClipper);
if(FAILED(hr))
{
AfxMessageBox(_T("Call to SetClipper failed"));
return E_FAIL;
}
hr = m_pDDClipper->SetHWnd(0, AfxGetMainWnd()->m_hWnd);
if(FAILED(hr))
{
AfxMessageBox(_T("Call to SetHWnd failed"));
return E_FAIL;
}
return NOERROR;
}
//Renders a file to a multimedia stream
HRESULT CMovieView::RenderFileToMMStream(LPCTSTR szFilename) //IMultiMediaStream **ppMMStream
{
IAMMultiMediaStream *pAMStream;
HRESULT hr = CoCreateInstance(CLSID_AMMultiMediaStream, NULL,
CLSCTX_INPROC_SERVER, IID_IAMMultiMediaStream,
(void **)&pAMStream);
if (FAILED(hr))
{
return hr;
}
WCHAR wPath[MAX_PATH + 1];
MultiByteToWideChar(CP_ACP, 0, szFilename, -1, wPath, MAX_PATH + 1);
pAMStream->Initialize(STREAMTYPE_READ, AMMSF_NOGRAPHTHREAD, NULL);
pAMStream->AddMediaStream(m_pDD, &MSPID_PrimaryVideo, 0, NULL);
pAMStream->AddMediaStream(NULL, &MSPID_PrimaryAudio, AMMSF_ADDDEFAULTRENDERER, NULL);
hr = pAMStream->OpenFile(wPath, 0);
if (SUCCEEDED(hr))
{
hr = pAMStream->QueryInterface(IID_IMultiMediaStream,
(void**)&m_pMMStream);
}
pAMStream->Release();
return hr;
// return NOERROR;
}
//Crea
没有合适的资源?快使用搜索试试~ 我知道了~
经典的vc++电影播放器
共25个文件
h:6个
cpp:5个
ico:2个
需积分: 10 31 下载量 92 浏览量
2008-10-09
22:42:52
上传
评论
收藏 65KB RAR 举报
温馨提示
源码播放器,用vc写的很好,你一定会喜欢的
资源推荐
资源详情
资源评论
收起资源包目录
21章 电影播放器.rar (25个子文件)
第21章 电影播放器
25-MoviePlay
MovieDoc.cpp 2KB
MovieDoc.h 1KB
StdAfx.cpp 251B
MovieApp.opt 82KB
resource.h 866B
MoviePlay.exe 26KB
MovieApp.ncb 97KB
MovieApp.h 1KB
MovieApp.dsp 5KB
MainFrame.h 2KB
MovieView.cpp 16KB
MovieApp.rc 11KB
MovieApp.dsw 542B
MovieApp.001 5KB
Debug
StdAfx.h 1KB
MainFrame.cpp 3KB
MovieApp.aps 30KB
MovieApp.clw 2KB
MovieView.h 5KB
MovieApp.plg 2KB
res
MovieMFC.rc2 404B
MovieMFC.ico 1KB
Toolbar.bmp 1KB
MovieDoc.ico 1KB
MovieApp.cpp 4KB
共 25 条
- 1
资源评论
jiangnan_120
- 粉丝: 0
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功