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.
A version of this page is also available for
4/8/2010

The following code does not include the functions WinMain or WindowProc. See the sample code in Sample Video Window Programfor these functions.

Note:
To make the following code example easier to read, error checking is not included. Do not use this code example in a release configuration unless it you have modified it to include secure error handling. Filenames in Windows Embedded CE start with "\\", not a drive letter.
Copy Code
#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);
	// Filenames start with a \\ instead of a drive letter.
	pGraph->RenderFile(L"\\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();
	pGraph = NULL;

	pVidWin->Release();
	pVidWin = NULL;
	pMediaControl = NULL;
	pEvent = NULL;

	PostQuitMessage(0);
}

void HandleEvent() 
{
	long evCode, param1, param2;
	HRESULT hr;
	while (hr = pEvent->GetEvent(&evCode, &param1,
&param2, 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.

See Also