Click here to Skip to main content
15,896,207 members

How to play the same video in two windows (Parent and child dialog box).

J.Surjith Kumar asked:

Open original thread
Am Playing the video by creating the filter graph using directshow in MFC. If i press the control which is in the parent dialog box i need to play the video in parent dialog box as well as child dialog box. The video was played in parent dialog box, to play as well as in child window what i have to do.

Here is my code:

C++
// playbackControls1Dlg.cpp : implementation file
// CplaybackControls1Dlg dialog
CplaybackControls1Dlg::CplaybackControls1Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CplaybackControls1Dlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	z=new CZoom;
}
// CplaybackControls1Dlg message handlers
BOOL CplaybackControls1Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	// Add "About..." menu item to system menu.
	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}
	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	// TODO: Add extra initialization here
        // Create the filter graph manager and query for interfaces.
    hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, 
                        IID_IGraphBuilder, (void **)&pGraph);
    if (FAILED(hr))
    {
        MessageBox(L"ERROR - Could not create the Filter Graph Manager.");
        return FALSE;
    }
    hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
    hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
    IMediaEventEx *g_pEvent = NULL;
    pGraph->QueryInterface(IID_IMediaEventEx, (void **)&pEvent);
    hr = InitWindowlessVMR(AfxGetMainWnd()->m_hWnd, pGraph, &pWc);
    hr=pGraph->RenderFile(L"C:\\Documents and Settings\\BTC\\Desktop\\hai.mp4", NULL);
    VideoSize();	
    return TRUE;  // return TRUE  unless you set the focus to a control
}
void CplaybackControls1Dlg::OnBnClickedPlayButton()
{
	// TODO: Add your control notification handler code here
	
	hr = pEvent->SetNotifyWindow((OAHWND)AfxGetMainWnd()->m_hWnd, WM_GRAPHNOTIFY, 0);

	if (SUCCEEDED(hr))
    {
        // Run the graph.
        hr = pControl->Run();
	z->ShowWindow(SW_SHOW);
    }
}
HRESULT CplaybackControls1Dlg::InitWindowlessVMR( 
    HWND hwndApp,                  // Window to hold the video. 
    IGraphBuilder* pGraph,         // Pointer to the Filter Graph Manager. 
    IVMRWindowlessControl** ppWc   // Receives a pointer to the VMR.
    ) 
{ 
    if (!pGraph || !ppWc) 
    {
        return E_POINTER;
    }
    IBaseFilter* pVmr = NULL; 
    IVMRWindowlessControl* pWc = NULL; 
    // Create the VMR. 
    HRESULT hr = CoCreateInstance(CLSID_VideoMixingRenderer, NULL, 
        CLSCTX_INPROC, IID_IBaseFilter, (void**)&pVmr); 
    if (FAILED(hr))
    {
        return hr;
    }   
    // Add the VMR to the filter graph.
    hr = pGraph->AddFilter(pVmr, L"Video Mixing Renderer"); 
    if (FAILED(hr)) 
    {
        pVmr->Release();
        return hr;
    }
    // Set the rendering mode.  
    IVMRFilterConfig* pConfig; 
    hr = pVmr->QueryInterface(IID_IVMRFilterConfig, (void**)&pConfig); 
    if (SUCCEEDED(hr)) 
    { 
        hr = pConfig->SetRenderingMode(VMRMode_Windowless); 
        pConfig->Release(); 
    }
    if (SUCCEEDED(hr))
    {
        // Set the window. 
        hr = pVmr->QueryInterface(IID_IVMRWindowlessControl, (void**)&pWc);
        if( SUCCEEDED(hr)) 
        { 
            hr = pWc->SetVideoClippingWindow(hwndApp); 
            if (SUCCEEDED(hr))
            {
                *ppWc = pWc; // Return this as an AddRef'd pointer. 
            }
            else
            {
                // An error occurred, so release the interface.
                pWc->Release();
            }
        } 
    } 
    pVmr->Release(); 
    return hr; 
} 
int CplaybackControls1Dlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  Add your specialized creation code here
	z->Create(IDD_DIALOG1,this);
	z->ShowWindow(FALSE);
	return 0;
}
LRESULT CplaybackControls1Dlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
	// TODO: Add your specialized code here and/or call the base class
switch(message)
{
case WM_GRAPHNOTIFY:
	HandleGraphEvent();
    break;
case WM_CLOSE:
	CleanUp();
	break;
}
	return CDialog::WindowProc(message, wParam, lParam);
}
void CplaybackControls1Dlg::HandleGraphEvent()
{
    // Disregard if we don't have an IMediaEventEx pointer.
    if (pEvent == NULL)
    {
        return;
    }
    // Get all the events
    long evCode;
    LONG_PTR param1, param2;
    while (SUCCEEDED(pEvent->GetEvent(&evCode, ¶m1, ¶m2, 0)))
    {
        pEvent->FreeEventParams(evCode, param1, param2);
        switch (evCode)
        {
        case EC_COMPLETE:  // Fall through.
        case EC_USERABORT: // Fall through.
        case EC_ERRORABORT:
	pControl->Stop();
        pEvent->SetNotifyWindow(NULL, 0, 0);
        return;
        }
    } 
}
void CplaybackControls1Dlg::CleanUp()
{
	pWc->Release();
        pControl->Release();
        pGraph->Release();
	pEvent->Release();
}
void CplaybackControls1Dlg::VideoSize()
{
	long lWidth, lHeight; 
	hr = pWc->GetNativeVideoSize(&lWidth, &lHeight, NULL, NULL); 
	if (SUCCEEDED(hr))
	{
		RECT rcSrc, rcDest; 
		// Set the source rectangle.
		SetRect(&rcSrc, 0, 0, lWidth, lHeight);
		// Get the window client area.
		GetClientRect(&rcDest); 
		// Set the destination rectangle.
		SetRect(&rcDest, 0, 40, rcDest.right, rcDest.bottom); 
	    	// Set the video position.
		hr = pWc->SetVideoPosition(&rcSrc, &rcDest); 
	}
	
}


CZoom is the child window.
This code is for playing the video in the parent window. What changes i have to make to play the video in the child.

Thank You in advance,
Tags: C++, C, MFC

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900