DirectShow's Chinese Data Control Video Play Window

zhaozj2021-02-11  198

Mainly explains how to control the video back window, all things don't say, you can refer to the code in "I. Playing the Movie". Needed header: #include #include #include

Define a window message and helper_release macro. #Define WM_GraphNotify WM_USER 13 #define helper_release (x) {if (x) x-> release (); x = null;}

Numerical variable: hnstance ghinst; hResult HR; long evcode; long evram1; long evram2; Rect GRC; parameter meaning and "playback movie", the only thing to explain, the GRC will save the parent window Area.

State and initialize the interface. Since the index value of the interface is automatic plus 1, you don't call the iUnknown :: AddRef method (if you feel strange, you can refer to the "First, DirectX and Parts Object Model COM" of the review). IgraphBuilder * Pigb = null; iMediacontrol * pimc = null; iMediaeventEx * Pimex = null; iVideoWindow * pivw = null;

Define a function: SZFile parameter is the media file name Void PlayMovieInWindow (LPCTSTSTSZFILE) {instantiated a Filter Graph Manager. HR = COCREATEINSTANCE (CLSID_FILTERGRAPH, NULL, CLSCTX_INPROC_SERVER, IID_IGRAPHBUILDER, (Void **) & Pigb);

Query the iMediaControl interface (providing Run, Pause and Stop Methods), iMediaEventEx interface (you can receive event response), iVideoWindow interface. pigb-> QueryInterface (IID_IMediaControl, (void **) & pimc); pigb-> QueryInterface (IID_IMediaEventEx, (void **) & pimex); pigb-> QueryInterface (IID_IVideoWindow, (void **) & pivw);

Let Filter Graph Manager build FILTER GRAPH to render input files. There is no playing file yet (when you play with the RUN function, the Filter Graph automatically renders the media type of the input file, you don't have to specify the rendering filter). HR = Pigb-> Renderfile (WFILE, NULL); Sets the handle of the playback window: PIVW-> Put_owner (OAHWND) GHAPP);

Set the style of the video window. This is important, you must specify WS_CHILD, WS_CLIPCHILDREN, and WS_CLIPSIBLINGS flags. PIVW-> PUT_WINDOWSTYLE (WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);

Get the customer area of ​​the parent window. GetClientRect (ghapp, & grc);

Set the location of the playback window in the client area of ​​the parent window. Here, the playback window filled with the customer area, of course, you can also take part. If the video is played than this small, he will automatically stretch the size of the position. If it is better than this, he will shrink to adapt. Pivw-> setWindowPosition (Grc.Lrc.top, Grc.right, Grc.bottom); start broadcasting: hr = pimc-> run ();

转载请注明原文地址:https://www.9cbs.com/read-4321.html

New Post(0)