|
这是我的源代码:
void CNewAviTestDlg::OnButton1()
{
// TODO: Add your control notification handler code here
IGraphBuilder *m_pGraph;
IMediaControl *m_pControl;
IMediaEventEx *m_pEvent;
IVideoWindow *m_pVideoWindow;
CoInitialize(NULL);
//hWnd = GetDlgItem(IDC_STATIC_MPEG)->m_hWnd; IDC_STATIC_MPEG是我的一个PictureBox控件的ID,我一开始是想用这个PictureBox控件作为播放avi窗口的,也是碰到同样的问题
HWND hWnd = GetSafeHwnd(); //所以现在我想把当前活动窗口作为播放窗口,也碰到了同样的问题。
HRESULT hr;
//free(); //Deletes any previous DirectShow instances
hr = CoCreateInstance(CLSID_FilterGraph, NULL,CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&m_pGraph);
if (!SUCCEEDED(hr))
{
MessageBox(_T("CoCreateInstance failed"));
}
hr = m_pGraph->QueryInterface(IID_IMediaControl, (void **)&m_pControl);
if (!SUCCEEDED(hr))
{
MessageBox(_T("IID_IMediaControl failed"));
}
hr = m_pGraph->QueryInterface(IID_IMediaEventEx, (void **)&m_pEvent);
if (!SUCCEEDED(hr))
{
MessageBox(_T("IID_IMediaEventEx failed"));
}
hr = m_pEvent->SetNotifyWindow((OAHWND)hWnd, 0, 0);
if (!SUCCEEDED(hr))
{
MessageBox(_T("SetNotifyWindow failed"));
}
hr = m_pGraph->RenderFile(L"C\\爱我别走.avi", NULL);
if (!SUCCEEDED(hr))
{
MessageBox(_T("RenderFile failed"));
//m_pMediaPlayerLog->WriteOut("RenderFile failed,RESULT:0x%x",hr);
}
hr = m_pGraph->QueryInterface(IID_IVideoWindow, (LPVOID *) &m_pVideoWindow);
if (!SUCCEEDED(hr))
{
MessageBox(_T("IID_IVideoWindow failed"));
}
SetWindowLong(hWnd,GWL_STYLE,GetWindowStyle(hWnd) ?WS_CLIPCHILDREN);
hr = pVidWin->put_Owner((OAHWND)hWnd);
CString strError;
if (!SUCCEEDED(hr))
{
strError.Format(_T("put_Owner出错:%x"),hr); //这里开始报错!!!
MessageBox(strError);
strError.Format(_T("put_Owner出错:%d"),hr);
MessageBox(strError);
strError.Format(hr);
MessageBox(strError);
}
hr = m_pVideoWindow->put_WindowStyle(WS_CHILD ?WS_CLIPCHILDREN ?WS_CLIPSIBLINGS); //然后这里也会报错 ,失败了
if (!SUCCEEDED(hr))
{
MessageBox(_T("put_WindowStyle failed"));
//m_pMediaPlayerLog->WriteOut("put_WindowStyle failed,RESULT:0x%x",hr);
}
hr = m_pVideoWindow->put_MessageDrain((OAHWND)hWnd);//然后这里也会报错 ,失败了
if (!SUCCEEDED(hr))
{
MessageBox(_T("put_MessageDrain failed"));
//m_pMediaPlayerLog->WriteOut("put_MessageDrain failed,RESULT:0x%x",hr);
}
hr = m_pVideoWindow->put_Visible(OATRUE); //最后是这里也会报错 ,失败了
if (!SUCCEEDED(hr))
{
MessageBox(_T("put_Visible failed"));
//m_pMediaPlayerLog->WriteOut("put_Visible failed,RESULT:0x%x",hr);
}
RECT grc;
GetClientRect(&grc);
m_pVideoWindow->SetWindowPosition(289,81,704,585);
m_pVideoWindow->put_Visible(OATRUE);
m_pControl->Run();
}
察看输出结果:
第一个对话框显示:put_Owner出错:80004002
第二个对话框显示:put_Owner出错:-2147467262
第三个对话框是空白
然后依次就出现下面三个对话框:
put_WindowStyle出错: 6
put_MessageDrain出错:6
put_Visible出错: 6
我想创建一个视频窗口,播放avi。谁能告诉我put_Owner()里面的参数应该怎么得到才不会出现那样的错误阿?谢谢大家!
我已经被这个问题困扰了3个星期了,有的人说这段代码在他的板子上是不会出现这些问题的,可是在我的板子上只听到几声“咔”的声音,没有图像。这是为什么啊?
该加的头文件
#include
#include
#pragma comment (lib,"Ole32.lib")
#pragma comment (lib,"Strmiids.lib")
我也都已经加了,可还是不明白为什么会出现那样的问题。
希望哪位高人能指点一下,视频窗口到底应该怎么创建。就算出200分我也愿意!!!谢谢!!!
|
|