|Microsoft DirectX 9.0|
In windowed mode, the video renderer creates a window, onto which it paints the video frames. Most of the time, you will want to attach this window to one of your own application windows.
Note The Video Renderer filter always uses windowed mode. The VMR-7 and VMR-9 both default to windowed mode, but they also support windowless mode.
Unless you specify otherwise, the video renderer's window is a top-level window with its own borders and title bar. To make the video appear within your own application window, make the video window a child of the application window. This is done by setting the video window's owner, style, and position, through the IVideoWindow interface.
Before starting playback, query the Filter Graph Manager for the IVideoWindow interface:
IVideoWindow *pVidWin = NULL; pGraph->QueryInterface(IID_IVideoWindow, (void **)&g_pVidWin);
Call the IVideoWindow::put_Owner method with a handle to your application window. This method takes a variable of type OAHWND, so cast the handle to this type:
Change the style of the video window by calling the IVideoWindow::put_WindowStyle method:
pVidWin->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS);
The WS_CHILD flag sets the window to be a child window, and the WS_CLIPSIBLINGS flag prevents the window from drawing inside the client area of another child window.
To set the position of the video relative to your window's client area, call the IVideoWindow::SetWindowPosition method. This method takes a rectangle that specifies the left edge, top edge, width, and height of the video window. For example, the following code stretches the video window to fit the entire client area of the parent window:
RECT grc; GetClientRect(hwnd, &grc); pVidWin->SetWindowPosition(0, 0, grc.right, grc.bottom);
You can also get the native size of the video by calling the IBasicVideo::GetVideoSize method on the Filter Graph Manager. You can use that information to scale the video and keep the correct aspect ratio.
Before the application exits, stop the graph and reset the video window's owner to NULL. Otherwise, window messages might be sent to the wrong window, which is likely to cause errors. Also, hide video window, or else you might see a video image flicker on the screen momentarily:
pControl->Stop(); pVidWin->put_Visible(OAFALSE); pVidWin->put_Owner(NULL);