Important: |
---|
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
The following code does not include the functions WinMain or WindowProc. See the sample code in Setting the Video Windowfor these functions.
#include <windows.h> #include <streams.h> #define WM_GRAPHNOTIFY WM_APP + 1 #define CLASSNAME "EventNotify" IGraphBuilder *pGraph = NULL; IMediaControl *pMediaControl = NULL; IMediaEventEx *pEvent = NULL; HWND g_hwnd; void PlayFile(void) { // Create the filter graph manager and render the file. CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC, IID_IGraphBuilder, (void **)&pGraph); pGraph->RenderFile(L"C:\\Media\\Boys.avi", NULL); // Specify the owner window. IVideoWindow *pVidWin = NULL; pGraph->QueryInterface(IID_IVideoWindow, (void **)&pVidWin); pVidWin->put_Owner((OAHWND)g_hwnd); pVidWin->put_WindowStyle( WS_CHILD | WS_CLIPSIBLINGS); // Set the owner window to receive event notices. pGraph->QueryInterface(IID_IMediaEventEx, (void **)&pEvent); pEvent->SetNotifyWindow((OAHWND)g_hwnd, WM_GRAPHNOTIFY, 0); // Run the graph. pGraph->QueryInterface(IID_IMediaControl, (void **)&pMediaControl); pMediaControl->Run(); } void CleanUp(void) { IVideoWindow *pVidWin = NULL; pGraph->QueryInterface(IID_IVideoWindow, (void **)&pVidWin); pVidWin->put_Visible(OAFALSE); pVidWin->put_Owner(NULL); // Stop the graph. pMediaControl->Stop(); long evCode; pEvent->WaitForCompletion(INFINITE, &evCode); pMediaControl->Release(); pEvent->Release(); pGraph->Release(); PostQuitMessage(0); } void HandleEvent() { long evCode, param1, param2; HRESULT hr; while (hr = pEvent->GetEvent(&evCode, ¶m1, ¶m2, 0), SUCCEEDED(hr)) { hr = pEvent->FreeEventParams(evCode, param1, param2); if ((EC_COMPLETE == evCode) || (EC_USERABORT == evCode)) { CleanUp(); break; } } } /* WindowProc goes here. Add the following case statement: case WM_GRAPHNOTIFY: HandleEvent(); break; */ // WinMain goes here.
Last updated on Tuesday, May 18, 2004