source: trunk/Utilities/Miscellaneous/MfcWindowlessVideoRenderer01/MainDialog.cpp @ 281

Last change on this file since 281 was 281, checked in by roman, 10 years ago
File size: 5.0 KB
Line 
1////////////////////////////////////////////////////////////
2// MainDialog.cpp : implementation file
3//
4// Copyright (C) Alax.Info, 2006-2008
5// http://alax.info
6//
7// A permission to use the source code is granted as long as reference to
8// source website http://alax.info is retained.
9//
10// Created by Roman Ryltsov roman@alax.info
11//
12// $Id: MainDialog.cpp 14 2008-11-19 09:23:16Z alax $
13
14#include "stdafx.h"
15#include "MfcWindowlessVideoRenderer01.h"
16#include "MainDialog.h"
17
18#ifdef _DEBUG
19#define new DEBUG_NEW
20#endif
21
22
23// CMainDialog dialog
24
25
26
27
28CMainDialog::CMainDialog(CWnd* pParent /*=NULL*/)
29        : CDialog(CMainDialog::IDD, pParent)
30{
31        m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
32}
33
34void CMainDialog::DoDataExchange(CDataExchange* pDX)
35{
36        CDialog::DoDataExchange(pDX);
37}
38
39BEGIN_MESSAGE_MAP(CMainDialog, CDialog)
40        //{{AFX_MSG_MAP
41        ON_WM_PAINT()
42        ON_WM_QUERYDRAGICON()
43        //ON_WM_INITDIALOG()
44        ON_WM_DESTROY()
45        ON_BN_CLICKED(IDC_START, &CMainDialog::OnBnClickedStart)
46        ON_BN_CLICKED(IDC_STOP, &CMainDialog::OnBnClickedStop)
47        //}}AFX_MSG_MAP
48END_MESSAGE_MAP()
49
50
51// CMainDialog message handlers
52
53BOOL CMainDialog::OnInitDialog()
54{
55        CDialog::OnInitDialog();
56
57        // Set the icon for this dialog.  The framework does this automatically
58        //  when the application's main window is not a dialog
59        SetIcon(m_hIcon, TRUE);                 // Set big icon
60        SetIcon(m_hIcon, FALSE);                // Set small icon
61
62        // TODO: Add extra initialization here
63        GetDlgItem(IDC_STOP)->EnableWindow(FALSE);
64
65        return TRUE;  // return TRUE  unless you set the focus to a control
66}
67
68VOID CMainDialog::OnDestroy()
69{
70        OnBnClickedStop();
71        __super::OnDestroy();
72}
73
74// If you add a minimize button to your dialog, you will need the code below
75//  to draw the icon.  For MFC applications using the document/view model,
76//  this is automatically done for you by the framework.
77
78void CMainDialog::OnPaint()
79{
80        if (IsIconic())
81        {
82                CPaintDC dc(this); // device context for painting
83
84                SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
85
86                // Center icon in client rectangle
87                int cxIcon = GetSystemMetrics(SM_CXICON);
88                int cyIcon = GetSystemMetrics(SM_CYICON);
89                CRect rect;
90                GetClientRect(&rect);
91                int x = (rect.Width() - cxIcon + 1) / 2;
92                int y = (rect.Height() - cyIcon + 1) / 2;
93
94                // Draw the icon
95                dc.DrawIcon(x, y, m_hIcon);
96        }
97        else
98        {
99                CDialog::OnPaint();
100        }
101}
102
103// The system calls this function to obtain the cursor to display while the user drags
104//  the minimized window.
105HCURSOR CMainDialog::OnQueryDragIcon()
106{
107        return static_cast<HCURSOR>(m_hIcon);
108}
109
110void CMainDialog::OnBnClickedStart()
111{
112        CreateGraph(m_pGraphs[0], IDC_VIDEO1);
113        CreateGraph(m_pGraphs[1], IDC_VIDEO2);
114        GetDlgItem(IDC_START)->EnableWindow(FALSE);
115        GetDlgItem(IDC_STOP)->EnableWindow(TRUE);
116}
117
118void CMainDialog::OnBnClickedStop()
119{
120        GetDlgItem(IDC_STOP)->EnableWindow(FALSE);
121        DestroyGraph(m_pGraphs[0]);
122        DestroyGraph(m_pGraphs[1]);
123        GetDlgItem(IDC_START)->EnableWindow(TRUE);
124}
125
126VOID CMainDialog::CreateGraph(CGraph& Graph, INT nControlIdentifier)
127{
128        CWnd* pWindow = GetDlgItem(nControlIdentifier);
129        ASSERT(pWindow);
130        ASSERT(!Graph.m_pGraphBuilder);
131        CComPtr<IGraphBuilder> pGraphBuilder;
132        ATLENSURE_SUCCEEDED(pGraphBuilder.CoCreateInstance(CLSID_FilterGraph));
133        CComPtr<IBaseFilter> pBaseFilter;
134        ATLENSURE_SUCCEEDED(pBaseFilter.CoCreateInstance(CLSID_VideoMixingRenderer9));
135    ATLENSURE_SUCCEEDED(pGraphBuilder->AddFilter(pBaseFilter, NULL));
136        CComQIPtr<IVMRFilterConfig9> pVmrFilterConfig9 = pBaseFilter;
137        ATLENSURE_THROW(pVmrFilterConfig9, E_NOINTERFACE);
138    ATLENSURE_SUCCEEDED(pVmrFilterConfig9->SetRenderingMode(VMR9Mode_Windowless));
139        CComQIPtr<IVMRWindowlessControl9> pVmrWindowlessControl9 = pBaseFilter;
140        ATLENSURE_THROW(pVmrWindowlessControl9, E_NOINTERFACE);
141    ATLENSURE_SUCCEEDED(pVmrWindowlessControl9->SetVideoClippingWindow(pWindow->GetSafeHwnd()));
142        CRect Position;
143        pWindow->GetClientRect(Position);
144        Position.InflateRect(4, 4);
145        ATLENSURE_SUCCEEDED(pVmrWindowlessControl9->SetVideoPosition(NULL, Position));
146    ATLENSURE_SUCCEEDED(pVmrWindowlessControl9->SetBorderColor(RGB(0x00, 0x00, 0x00)));
147        TCHAR pszPath[MAX_PATH] = { 0 };
148        ATLVERIFY(GetWindowsDirectory(pszPath, _countof(pszPath)));
149        ATLVERIFY(PathCombine(pszPath, pszPath, _T("clock.avi")));
150        ATLENSURE_SUCCEEDED(pGraphBuilder->RenderFile(CStringW(pszPath), NULL));
151        Graph.m_pGraphBuilder = pGraphBuilder;
152        Graph.m_pVmrWindowlessControl9 = pVmrWindowlessControl9;
153        TRY
154        {
155                CComQIPtr<IMediaControl> pMediaControl = pGraphBuilder;
156                ATLENSURE_THROW(pMediaControl, E_NOINTERFACE);
157                ATLENSURE_SUCCEEDED(pMediaControl->Run());
158        }
159        CATCH_ALL(pException)
160        {
161                DestroyGraph(Graph);
162                pException->Delete();
163        }
164        END_CATCH_ALL
165}
166
167VOID CMainDialog::DestroyGraph(CGraph& Graph)
168{
169        CComQIPtr<IMediaControl> pMediaControl = Graph.m_pGraphBuilder;
170        if(pMediaControl)
171                ATLVERIFY(SUCCEEDED(pMediaControl->Stop()));
172        Graph.m_pVmrWindowlessControl9 = NULL;
173        Graph.m_pGraphBuilder = NULL;
174}
175
Note: See TracBrowser for help on using the repository browser.