// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. // // Copyright (c) Microsoft Corporation. All rights reserved #include #include #include #include #include #include #include #include "resource.h" #include #include class CApplication { public: static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); static VOID ShowErrorMessage(PCWSTR format, HRESULT hr); static VOID OnMediaItemCreated(MFP_MEDIAITEM_CREATED_EVENT *pEvent); static VOID OnMediaItemSet(MFP_MEDIAITEM_SET_EVENT *pEvent); public: explicit CApplication(HINSTANCE hInstance); ~CApplication(); int Run(); private: CApplication(const CApplication &); private: HRESULT PlayMediaFile(); HRESULT Initialize(); // Initialize main window functions including layered child window HRESULT InitializeMainWindow(); HRESULT InitializeLayeredChildWindows(); HRESULT MoveLayeredChildWindows(); // Initialize Direct Composition and D3D functions HRESULT CreateD3D11Device(); HRESULT CreateDCompositionDevice(); HRESULT CreateDCompositionRenderTarget(); HRESULT CreateDCompositionVisualTree(); HRESULT CreateTransforms(); // Window message handlers LRESULT OnClose(HWND hwnd); HRESULT OnCommand(int id); LRESULT OnDestroy(HWND hwnd); HRESULT OnPaint(HWND hwnd); HRESULT OnRightClick(); HRESULT OnTimer(); // Direct Composition Transforms HRESULT OnRotate(); HRESULT OnScale(); HRESULT OnSkew(); HRESULT SetRotation(float beginRotationAngle, float beginTime, float endTime, IDCompositionRotateTransform *rotateTransform); HRESULT SetScaling(float beginScaleX, float beginScaleY, float endScaleX, float endScaleY, float beginTime, float endTime, IDCompositionScaleTransform *scaleTransform); HRESULT SetSkewing(float skewAngleX, float skewAngleY, float beginTime, float endTime, IDCompositionSkewTransform *skewTransform); HRESULT SetTranslation(float beginPositionX, float endPositionX, float beginPositionY, float endPositionY, float beginTime, float endTime, IDCompositionTranslateTransform *translateTransform); HRESULT CreateLinearAnimation(float beginValue, float endValue, float beginTime, float endTime, IDCompositionAnimation **linearAnimation); HRESULT CreateTranslateAnimation(float beginValue, float endValue, float beginTime, float endTime, IDCompositionAnimation **linearAnimation); // Cloak/uncloak windows HRESULT CloakWindow(BOOL cloakHwnd, HWND hwnd); int EnterMessageLoop(); // Destroy VOID Destroy(); VOID DestroyMainWindow(); VOID DestroyLayeredChildWindows(); VOID DestroyDCompositionVisualTree(); VOID DestroyDCompositionRenderTarget(); VOID DestroyDCompositionDevice(); VOID DestroyD3D11Device(); VOID DestroyTransforms(); private: static CApplication *s_application; static CComPtr s_pPlayer; static const float s_fanimationTime; HINSTANCE m_hInstance; WCHAR m_fontTypeface[32]; int m_fontHeightLogo; int m_fontHeightTitle; int m_fontHeightDescription; HWND m_hMainWindow; // Main window HWND m_hControlChildWindow; // Control window HWND m_hVideoChildWindow; // Video window HWND m_hTextChildWindow; // Text window HWND m_hwndButton[4]; // Control buttons CComPtr _d3d11Device; CComPtr _d3d11DeviceContext; CComPtr m_pDevice; CComPtr m_pHwndRenderTarget; CComPtr m_pRootVisual; CComPtr m_pControlChildVisual; CComPtr m_pTextChildVisual; CComPtr m_pVideoChildVisual; CComPtr m_pControlsurfaceTile; CComPtr m_pTextsurfaceTile; CComPtr m_pVideosurfaceTile; CComPtr m_pControlTranslateTransform; CComPtr m_pTextTranslateTransform; CComPtr m_pTransformGroup; CComPtr m_pRotateTransform; CComPtr m_pSkewTransform; CComPtr m_pScaleTransform; //MediaPlayerCallBack BOOL m_bControlOn; CComPtr s_pPlayerCB; enum { ID_PLAYSTOP, // Play/Stop button ID ID_ROTATE, // Rotate button ID ID_SCALE, // Scale button ID ID_SKEW, // Skew button ID IDT_TIMER // Timer ID }; }; // Implements the callback interface for MFPlay events. class MediaPlayerCallback : public IMFPMediaPlayerCallback { private: long m_cRef; // Reference count public: MediaPlayerCallback() : m_cRef(1) { } STDMETHODIMP QueryInterface(REFIID riid, void** ppv) { HRESULT hr = S_OK; *ppv = NULL; if (riid == __uuidof(IMFPMediaPlayerCallback)) { *ppv = static_cast(this); } else if (riid == __uuidof(IUnknown)) { *ppv = static_cast(this); } else { hr = E_NOINTERFACE; } if (SUCCEEDED(hr)) { AddRef(); } return hr; } STDMETHODIMP_(ULONG) AddRef() { return InterlockedIncrement(&m_cRef); } STDMETHODIMP_(ULONG) Release() { ULONG count = InterlockedDecrement(&m_cRef); if (count == 0) { delete this; } return count; } // IMFPMediaPlayerCallback methods void STDMETHODCALLTYPE OnMediaPlayerEvent(_In_ MFP_EVENT_HEADER *pEventHeader); };