www.pudn.com > STBIHOST.rar > osdwrapper.cpp
// // Copyright (c) Microsoft Corporation. All rights reserved. // // // Use of this source code is subject to the terms of the Microsoft end-user // license agreement (EULA) under which you licensed this SOFTWARE PRODUCT. // If you did not accept the terms of the EULA, you are not authorized to use // this source code. For a copy of the EULA, please see the LICENSE.RTF on your // install media. // /*++ 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. Module Name: osdwrapper.cpp Abstract: Implements IOSDWrapper; see header file for more info. --*/ #include "stdafx.h" #include "stbihost.h" #include#include "osdwrapper.h" EXTERN_C const IID IID_IActiveMovie = { 0x05589FA2, 0xC356, 0x11CE, { 0xBF, 0x01, 0x00, 0xAA, 0x00, 0x55, 0x59, 0x5A } }; extern HINSTANCE g_hInstance; void COSDWrapper::ResetInternalPointers() { if (m_pdispWMP) m_pdispWMP->Release(); if (m_pVideoWindow) m_pVideoWindow->Release(); if (m_pOSD) delete m_pOSD; m_pdispWMP = NULL; m_pVideoWindow = NULL; m_pOSD = NULL; } STDMETHODIMP COSDWrapper::InitForMediaPlayer(/*[in]*/ IDispatch* pVal) { if (!pVal) return E_POINTER; if (m_pdispWMP) m_pdispWMP->Release(); m_pdispWMP = pVal; m_pdispWMP->AddRef(); return S_OK; } STDMETHODIMP COSDWrapper::SignalOpenState(/*[in]*/ VARIANT_BOOL fOpen) { DEBUGMSG(1, (TEXT("COSDWrapper::SignalOpenState(%s)\r\n"), VARIANT_TRUE == fOpen ? TEXT("TRUE") : TEXT("FALSE"))); if (m_pOSD) { delete [] m_pOSD; m_pOSD = NULL; } if (!fOpen) return S_OK; ASSERT(m_pdispWMP); if (!m_pdispWMP) return E_UNEXPECTED; HRESULT hr; IActiveMovie* pActiveMovie = NULL; IUnknown* pUnkFilterGraph = NULL; // make sure we have access to IVideoWindow hr = m_pdispWMP->QueryInterface(IID_IActiveMovie, (void**)&pActiveMovie); if (SUCCEEDED(hr)) { hr = pActiveMovie->get_FilterGraph(&pUnkFilterGraph); if (SUCCEEDED(hr)) { hr = pUnkFilterGraph->QueryInterface(IID_IVideoWindow, (void**)&m_pVideoWindow); if (SUCCEEDED(hr)) { HWND hwnd; hr = m_pVideoWindow->get_Owner(reinterpret_cast (&hwnd)); if (SUCCEEDED(hr)) { // get child window from owner POINT pt = {320, 240}; HWND hwndChild = ChildWindowFromPoint(hwnd, pt); // now we have the info we need to init // the OSD m_pOSD = new CWinOSD(); if (!m_pOSD) hr = E_OUTOFMEMORY; else hr = m_pOSD->SetWindow(hwndChild, g_hInstance); } } } } if (FAILED(hr)) ResetInternalPointers(); if (pActiveMovie) pActiveMovie->Release(); if (pUnkFilterGraph) pUnkFilterGraph->Release(); return hr; } STDMETHODIMP COSDWrapper::ProvideFeedback(long cmd, long cmdResult) { if (!m_pOSD) return E_UNEXPECTED; if (cmd < NoCmd || cmd >= End) return E_INVALIDARG; m_pOSD->ProvideFeedback((CPlayerCommand)cmd, cmdResult); return S_OK; }