在CStatic上显示视频
把视频显示在CStatic上,上一篇讲了怎么播放一个视频,但是如果要嵌在对话框之类的窗体上面的话,就需要用IVideoWindow接口,通过pWindow->put_Owner((OAHWND)m_Screen.GetSafeHwnd());就可以指定pWindow是显示在m_Screen控件上面了
IGraphBuilder *pGraph;
IMediaControl *pControl;
IMediaEventEx *pEvent;
IVideoWindow *pWindow;
HRESULT hr = CoInitialize(NULL);
if (FAILED(hr))
{
// Add error-handling code here. (Omitted for clarity.)
}
CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC,
IID_IGraphBuilder, (void **)&pGraph);
pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
pGraph->QueryInterface(IID_IVideoWindow, (void **)&pWindow);
pGraph->QueryInterface(IID_IMediaEventEx, (void **)&pEvent);
pEvent->SetNotifyWindow((OAHWND)m_Screen.GetParent()->m_hWnd, WM_GRAPHNOTIFY, 0);
hr = pGraph->RenderFile(L"D:\\yf.avi", NULL);
m_Screen.ModifyStyle(0, WS_CLIPCHILDREN);
if(pWindow)
{
//pWindow->put_MessageDrain((OAHWND) m_Screen.GetParent()->m_hWnd);
pWindow->put_Owner((OAHWND)m_Screen.GetSafeHwnd());
hr = pWindow->put_WindowStyle(WS_CHILD);
CRect rc;
m_Screen.GetClientRect(&rc);
int width = rc.right - rc.left;
int height = rc.bottom - rc.top;
pWindow->SetWindowPosition(rc.left,rc.top,width,height);
hr = pWindow->put_Visible(OATRUE);
hr = pWindow->SetWindowForeground(-1);
}
pControl->Run();
IMediaControl *pControl;
IMediaEventEx *pEvent;
IVideoWindow *pWindow;
HRESULT hr = CoInitialize(NULL);
if (FAILED(hr))
{
// Add error-handling code here. (Omitted for clarity.)
}
CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC,
IID_IGraphBuilder, (void **)&pGraph);
pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
pGraph->QueryInterface(IID_IVideoWindow, (void **)&pWindow);
pGraph->QueryInterface(IID_IMediaEventEx, (void **)&pEvent);
pEvent->SetNotifyWindow((OAHWND)m_Screen.GetParent()->m_hWnd, WM_GRAPHNOTIFY, 0);
hr = pGraph->RenderFile(L"D:\\yf.avi", NULL);
m_Screen.ModifyStyle(0, WS_CLIPCHILDREN);
if(pWindow)
{
//pWindow->put_MessageDrain((OAHWND) m_Screen.GetParent()->m_hWnd);
pWindow->put_Owner((OAHWND)m_Screen.GetSafeHwnd());
hr = pWindow->put_WindowStyle(WS_CHILD);
CRect rc;
m_Screen.GetClientRect(&rc);
int width = rc.right - rc.left;
int height = rc.bottom - rc.top;
pWindow->SetWindowPosition(rc.left,rc.top,width,height);
hr = pWindow->put_Visible(OATRUE);
hr = pWindow->SetWindowForeground(-1);
}
pControl->Run();