If you need to render with windowed mode, you need the following steps:
- Querying the Ivideowindow interface (QueryInterface)
- Set parent window (Put_owner)
- Setting the window mode (put_windowstyle)
- Setting the window position (setwindowposition)
- Handling Wm_move Messages
Process explanatory code, shorthand, no return value to judge
HRESULT hr=CoInitialize (NULL); Igraphbuilder*Pgraphbuilder; HR=cocreateinstance (Clsid_filtergraph,null,clsctx_inproc_server,iid_igraphbuilder, (void* *) &Pgraphbuilder); Pgraphbuilder->renderfile (L"D:\\direct_show\\extras\\directshow\\samples\\media\\video\\ruby.avi",0); Ivideowindow*pvideowin=NULL; HR=pgraphbuilder->queryinterface (Iid_ivideowindow, (void* *) &Pvideowin); HR=pvideowin->Put_owner ((Oahwnd) m_hwnd); HR=pvideowin->put_windowstyle (Ws_child |ws_clipsiblings); Rect rect; GetClientRect (&rect); HR=pvideowin->setwindowposition (0,0, Rect.right,rect.bottom); IMediaControl*Pcontrol; Imediaevent*pevent; HR=pgraphbuilder->queryinterface (Iid_imediacontrol, (void* *) &Pcontrol); HR=pgraphbuilder->queryinterface (Iid_imediaevent, (void* *) &pevent); Pcontrol-Run (); LongEvcode=0; HR=pevent->waitforcompletion (infinite,&Evcode); Pcontrol-Release (); Pevent-Release (); Pgraphbuilder-Release (); CoUninitialize ();
Case wm_move: pvidwin-notifyownermessage ((oahwnd) hWnd, MSG, WParam, lParam); break;
Cleanup work:
Pcontrol->Stop (); Pvidwin-put_visible (oafalse);p vidwin->put_owner (NULL);
It is important to note that:
The call to the RenderFile function must precede the Put_owner function, or the return value of the Put_owner function is s_nointerface.
In this example, there is no shadow to add any filter, neither the source filter nor the render filter, just one sentence of RenderFile (). Yes, RenderFile () did all the things.
First Igraphbuilder::renderfile () calls Igraphbuilder::addsourcefilter () to add a source Filter to the graph. Igraphbuilder::addsourcefilter () intelligently selects a source Filter for a matching file based on the file name extension or the file first-class information.
Then Igraphbuilder::renderfile () calls Igraphbuilder::render () to complete the rest of the graph generation. Igraphbuilder::render () starts looking for each filter that matches this pin from the output pin of source filter to join the link until a Render filter is found. When the entire link is complete, it also represents graph generation, and you can call Pcontrol->run () to run graph.
Although Ivideowindow is exposed by the filter Graph Manager, the Ivideowindow setting property is for the render filter. RenderFile is not connected in graph until RenderFile is executed, so Ivideowindow's settings are not valid. (http://blog.csdn.net/bwmwm/article/details/4562709)
Windowed Mode Video Rendering