(100分求帮助)关于一个很简单的播放器问题

asdfghjo 2005-08-03 12:38:49
我刚刚开始学习VC++,按照这个上面说明http://tech.sina.com.cn/c/2001-11-05/6905.html做了个播放器模型,又参考DirectShow例子加进去实现播放的功能。现在有几个问题要问一下各位GGJJ~如何播放我选择的文件(因为目前只能播放那个地址下的文件),如何用stop button停止播放文件,如何点击播放时,播放窗口不再弹出而是图像显示在播放器左边的播放窗口~~~下面是我的源码,希望高手耐心帮助~~~急~在线等待!


#include "stdafx.h"
#include "player.h"
#include "playerDlg.h"
#include <dshow.h>
#include <stdio.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
CAboutDlg();

// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

CPlayerDlg::CPlayerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPlayerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPlayerDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CPlayerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPlayerDlg)
DDX_Control(pDX, IDC_ANIMATE2, m_animate);
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPlayerDlg, CDialog)
//{{AFX_MSG_MAP(CPlayerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_Exit, OnExit)
ON_BN_CLICKED(IDC_Play, OnPlay)
ON_BN_CLICKED(IDC_Select, OnSelect)
ON_NOTIFY(NM_OUTOFMEMORY, IDC_ANIMATE2, OnOutofmemoryAnimate2)
ON_BN_CLICKED(IDC_Stop, OnStop)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPlayerDlg message handlers

BOOL CPlayerDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here

return TRUE; // return TRUE unless you set the focus to a control
}

void CPlayerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}

// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.

void CPlayerDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}

// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CPlayerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}

void CPlayerDlg::OnOutofmemoryAnimate2(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here


*pResult = 0;
}

void CPlayerDlg::OnSelect()

{
CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY| OFN_OVERWRITEPROMPT,_T("|*.AVI|"));
if(dlg.DoModal()==IDOK)

m_filename=dlg.GetPathName( );

}

void CPlayerDlg::OnPlay()
{

playFile();

}
void CPlayerDlg::OnExit()

{
m_animate.Stop( );

m_animate.Close( );

CDialog::OnOK( );
}
void CPlayerDlg::OnStop()
{

}

void CPlayerDlg::playFile()
{
IGraphBuilder *pGraph = NULL;
IMediaControl *pControl = NULL;
IMediaEvent *pEvent = NULL;

// Initialize the COM library.
HRESULT hr = CoInitialize(NULL);
if (FAILED(hr))
{
printf("ERROR - Could not initialize COM library");
return;
}

// Create the filter graph manager and query for interfaces.
hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, (void **)&pGraph);
if (FAILED(hr))
{
printf("ERROR - Could not create the Filter Graph Manager.");
return;
}

hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);

// Build the graph. IMPORTANT: Change this string to a file on your system.
hr = pGraph->RenderFile(L"C:\\Documents and Settings\\lala\\Desktop\\laislabonita.wmv", NULL);
if (SUCCEEDED(hr))
{
// Run the graph.
hr = pControl->Run();
if (SUCCEEDED(hr))
{
// Wait for completion.
long evCode;
pEvent->WaitForCompletion(INFINITE, &evCode);

// Note: Do not use INFINITE in a real application, because it
// can block indefinitely.
}
}
pControl->Release();
pEvent->Release();
pGraph->Release();
CoUninitialize();
}
...全文
141 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
应该是CString::AllocSysString,呵呵,记错了
老夏Max 2005-08-03
  • 打赏
  • 举报
回复
当保存了窗口句柄以后也可以使用GetWindow判断窗口是否存在,如果不存在就创建,呵呵
快乐鹦鹉 2005-08-03
  • 打赏
  • 举报
回复
同意一楼。刚开始学,最好先做写简单一点的。慢慢的再集成做复杂一点的。不要想着一口吃成胖子。你提的这些问题。不是一句两句能说清楚的。而且你如果对这些都没有任何了解的话,也是很难理解的。循序渐进吧。
老夏Max 2005-08-03
  • 打赏
  • 举报
回复
可以使用IsWindow判断窗口是否存在。
老夏Max 2005-08-03
  • 打赏
  • 举报
回复
将播放窗口的变量作为成员变量,在Stop的时候使用ShowWindow(SW_HIDE)隐藏窗口而不是删除窗口,当再次播放的时候使用ShowWindow(SW_SHOW)再次显示这个窗口!
modena 2005-08-03
  • 打赏
  • 举报
回复
先学习MFC使用
学习CFileDialog的使用
学习C/C++参数的传递
然后研究DirectShow体系
研究IGraphBuilder/IMediaControl及IVideoWindow的关系及相关处理接口
再研究如何将IVideoWindow集成进入你的界面
asdfghjo 2005-08-03
  • 打赏
  • 举报
回复
To Ariesman(超然)

能具体说下从那篇开始吗??

Ariesman 2005-08-03
  • 打赏
  • 举报
回复
这种方法后别忘了要释放内存
SysFreeString

呵呵,这么一堆东西都是要注意的,其实你可以跟着DShow9的SDK帮助文件从头开始,没几篇就把你碰到的所有问题都解决了
Ariesman 2005-08-03
  • 打赏
  • 举报
回复
AllocSysString
asdfghjo 2005-08-03
  • 打赏
  • 举报
回复
To orbit(走了走了):
这个错误怎么修改?

Compiling...
playerDlg.cpp
C:\MY VC++\player\player\playerDlg.cpp(284) : error C2039: 'SysAllocString' : is not a member of 'CString'
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(368) : see declaration of 'CString'
Error executing cl.exe.

playerDlg.obj - 1 error(s), 0 warning(s)
DentistryDoctor 2005-08-03
  • 打赏
  • 举报
回复
从DirectShow上手学VC,是需要勇气的哟。
vcmute 2005-08-03
  • 打赏
  • 举报
回复
别忘了设置WS_CHILD属性
pWindow->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS);
  • 打赏
  • 举报
回复
BSTR bsName = m_filename.SysAllocString();

hr = pGraph->RenderFile(bsName, NULL);

SysFreeString(bsName);
vcmute 2005-08-03
  • 打赏
  • 举报
回复
别死等,如pEvent->WaitForCompletion(INFINITE, &evCode)

如何用stop button停止播放文件,
pControl->Stop()

如何点击播放时,播放窗口不再弹出而是图像显示在播放器左边的播放窗口
pWindow->put_Owner((OAHWND)m_hWnd);

pWindow是IVideoWindow*类型,QueryInterface一下
Practise_Think 2005-08-03
  • 打赏
  • 举报
回复
如果想跳跃式地学习恐怕得不偿失,是真的,我曾有过这样的经历!!

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧