|
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 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(_T("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
第三个对话框是空白
我想创建一个视频窗口,播放MP4。谁能告诉我put_Owner()里面的参数应该怎么得到才不会出现那样的错误阿?谢谢大家!
|
|