DirectShow control video playback window for Chinese Data

Source: Internet
Author: User

It mainly explains how to control Video Play back the window, nothing to say, you can refer to "1. Play Video "InCode.
Required header file:
# Include <windows. h>
# Include <mmsystem. h>
# Include <streams. h>

Defines a window message and a helper_release macro.
# Define wm_graphpolicy wm_user + 13
# Define helper_release (x) {If (x) x-> release (); X = NULL ;}

Declarative variables:
Hwnd ghapp;
Hinstance ghinst;
Hresult hr;
Long evcode;
Long evparam1;
Long evparam2;
Rect GRC;
The meaning of the parameter is the same as that of "1. Play a video". The only thing to note is GRC. Customer .

Declare and initialize required interfaces. Because the index value of the interface is automatically added with 1, you should not call the iunknown: addref method (if you are unfamiliar with it, you can refer to "I. DirectX and part object" in the summary article. Model Com ").
Igraphbuilder * pigb = NULL;
Imediacontrol * pimc = NULL;
Imediaeventex * pimex = NULL;
Ivideowindow * pivw = NULL;

Define a function: The szfile parameter is played. Media File Name
Void playmovieinwindow (lpctstr szfile)
{
 
Instantiate a filter graph manager.
HR = cocreateinstance (clsid_filtergraph,
Null,
Clsctx_inproc_server,
Iid_igraphbuilder,
(Void **) & pigb );

The imediacontrol interface (run, pause and stop methods), imediaeventex interface (you can receive event responses), and ivideowindow interface are provided.
Pigb-> QueryInterface (iid_imediacontrol, (void **) & pimc );
Pigb-> QueryInterface (iid_imediaeventex, (void **) & pimex );
Pigb-> QueryInterface (iid_ivideowindow, (void **) & pivw );

Let filter graph manager create filter graph to render the input file. The file has not been played yet (when you use the run function to play the video, filter graph will automatically render the media type of the input file, you do not have to specify the rendering Filter ).
HR = pigb-> renderfile (wfile, null );
 
Set the handle of the playback window:
Pivw-> put_owner (oahwnd) ghapp );

Set the video window Style . This step is very important. You must specify ws_child, ws_clipchildren, and ws_clipsiblings Flag .
Pivw-> put_windowstyle (ws_child | ws_clipchildren | ws_clipsiblings );

Obtain the customer area of the parent window.
Getclientrect (ghapp, & GRC );

Set the position of the playback window in the customer area of the parent window. Here, the playback window fills up the customer zone, and you can also take part of it. If the video to be played is smaller than this, it automatically scales out to adapt to the position. If it is larger, It scales down to adapt.
Pivw-> setwindowposition (GRC. Left, GRC. Top, GRC. Right, GRC. Bottom );

Start playing:
HR = pimc-> Run ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.