⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mpcontainer.cpp

📁 media player 控件源码 用EVC编译可以进行对WINCE下media player控制
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//
// 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.
//
///////////////////////////////////////////////////////////////////////////////
// File: MPContainer.cpp
//
// Desc: This file contains the implementation for the MPContainer class,
//       which is used to host the Windows Media Player ActiveX control.
//
///////////////////////////////////////////////////////////////////////////////

#include "MPContainer.h"
#include "PlayerWindow.h"

#include <olectl.h>
#include <msdxm.h>
#include <dsdispid.h>
#define _COMCTL32_
#include <commctrl.h>
#undef _COMCTL32_

#include "resource.h"

//////
// Constructor/Destructor
CMPContainer::CMPContainer() : m_ulRef(0),
m_hWnd(NULL),
m_pUnk(NULL),
m_pIPOW(NULL),
m_pIPO(NULL),
m_pMP(NULL),
#ifdef CEPLAYER_SKIN
m_dwLevelOfControls(10) // Skin
#else /* !CEPLAYER_SKIN */
m_dwLevelOfControls(2) // Standard level
#endif /* CEPLAYER_SKIN */
{
}

CMPContainer::~CMPContainer()
{
    Fini();
}

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::Init()
// Desc: This function does no work.
///////////////////////////////////////////////////////////////////////////////
bool CMPContainer::Init()
{
    return true;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::Fini()
// Desc: This function releases all interfaces held by the container.
///////////////////////////////////////////////////////////////////////////////
bool CMPContainer::Fini()
{
    return true;
}

//////
// IUnknown Methods

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::QueryInterface()
// Desc: This function is used to get various interfaces from this container.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::QueryInterface(REFIID riid, LPVOID *ppvObj)
{
    if (ppvObj == NULL)
    {
        return E_INVALIDARG;
    }
    
    *ppvObj = NULL;
    
    if (IsEqualIID(riid, IID_IDispatch))
    {
        *ppvObj = static_cast<IDispatch*>(this);
    }
    else if (IsEqualIID(riid, IID_IErrorInfo))
    {
        *ppvObj = static_cast<IErrorInfo*>(this);
    }
    else if (IsEqualIID(riid, IID_IOleClientSite))
    {
        *ppvObj = static_cast<IOleClientSite*>(this);
    }
    else if (IsEqualIID(riid, IID_IOleContainer))
    {
        *ppvObj = static_cast<IOleContainer*>(this);
    }
    else if (IsEqualIID(riid, IID_IOleControlSite))
    {
        *ppvObj = static_cast<IOleControlSite*>(this);
    }
    else if (IsEqualIID(riid, IID_IOleInPlaceFrame))
    {
        *ppvObj = static_cast<IOleInPlaceFrame*>(this);
    }
    else if (IsEqualIID(riid, IID_IOleInPlaceSite))
    {
        *ppvObj = static_cast<IOleInPlaceSite*>(this);
    }
    else if (IsEqualIID(riid, IID_IOleInPlaceSiteWindowless))
    {
        *ppvObj = static_cast<IOleInPlaceSiteWindowless*>(this);
    }
    else
    {
        return E_NOINTERFACE;
    }
    
    if (NULL != *ppvObj)
    {
        AddRef();
    }
    
    return S_OK;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::AddRef()
// Desc: This function increments the container's reference count.
///////////////////////////////////////////////////////////////////////////////
ULONG   CMPContainer::AddRef()
{
    m_ulRef++;
    
    return m_ulRef;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::Release()
// Desc: This function decrements the container's reference count and if
//       needed, destroys the object.
///////////////////////////////////////////////////////////////////////////////
ULONG   CMPContainer::Release()
{
#ifdef UNDER_CE
//    ASSERT(m_ulRef > 0);
#endif /* UNDER_CE */
    
    m_ulRef--;

    if (m_ulRef > 0)
    {
        return m_ulRef;
    }
    
    m_ulRef = 0;
    
    return 0;
}

//////
// IDispatch Methods

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::GetIDsOfNames()
// Desc: This function is used by a control to determine what functionality
//       is provided by the container.  All the names are set to UNKNOWN.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::GetIDsOfNames(REFIID riid, OLECHAR FAR* FAR* rgszNames, unsigned int uiNames, LCID lcid, DISPID FAR* rgdispid)
{
    HRESULT   hResult;
    unsigned int i;
    
    hResult = S_OK;
    
    for (i = 0; i < uiNames; i++)
    {
        if (rgszNames[i] != NULL)
        {
            rgdispid[i] = DISPID_UNKNOWN;
            hResult     = DISP_E_UNKNOWNNAME;
        }
    }
    
    return hResult;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::GetTypeInfo()
// Desc: Not implemented.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::GetTypeInfo(unsigned int, LCID, ITypeInfo FAR* FAR*)
{
    return E_NOTIMPL;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::GetTypeInfoCount()
// Desc: Not implemented.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::GetTypeInfoCount(unsigned int FAR*)
{
    return E_NOTIMPL;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::Invoke()
// Desc: This function is used by the control to access methods and properties
//       of the container.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::Invoke(DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR* pdispparams, VARIANT FAR* pvarResult, EXCEPINFO FAR* pexecinfo, unsigned int FAR* puArgErr)
{
    HRESULT hr = S_OK;
    
    if ((NULL == pvarResult) && (DISPATCH_PROPERTYGET == wFlags))
    {
        return E_INVALIDARG;
    }
    
    switch (dispid)
    {
    case DISPID_AMBIENT_USERMODE:
    case DISPID_AMBIENT_MESSAGEREFLECT:
        pvarResult->vt      = VT_BOOL;
        pvarResult->boolVal = TRUE;
        hr                  = S_OK;
        break;
    }
    
    return hr;
}

//////
// IErrorInfo Methods

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::GetGUID()
// Desc: Not implemented.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::GetGUID(GUID *pGUID)
{
    return E_NOTIMPL;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::GetSource()
// Desc: Not implemented.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::GetSource(BSTR *)
{
    return E_NOTIMPL;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::GetDescription()
// Desc: Not implemented.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::GetDescription(BSTR *)
{
    return E_NOTIMPL;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::GetHelpFile()
// Desc: Not implemented.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::GetHelpFile(BSTR *)
{
    return E_NOTIMPL;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::GetHelpContext()
// Desc: Not implemented.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::GetHelpContext(DWORD *)
{
    return E_NOTIMPL;
}

//////
// IOleClientSite Methods

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::SaveObject()
// Desc: Not implemented.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::SaveObject()
{
    return E_NOTIMPL;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::GetMoniker()
// Desc: Not implemented.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::GetMoniker(DWORD, DWORD, LPMONIKER *)
{
    return E_NOTIMPL;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::GetContainer()
// Desc: Not implemented.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::GetContainer(LPOLECONTAINER *)
{
    return E_NOTIMPL;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::ShowObject()
// Desc: This function directs the control to draw itself.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::ShowObject()
{
    if (NULL != m_pIPOW)
    {
        HDC hDC;
        IViewObjectEx *pVOEx = NULL;
        
        hDC = ::GetDC(m_hWnd);
        
        if (NULL == hDC)
        {
            return S_FALSE;
        }
        
        if (NULL != m_pUnk)
        {
            m_pUnk->QueryInterface(IID_IViewObjectEx, reinterpret_cast<void**>(&pVOEx));
        }
        
        if (NULL != pVOEx)
        {
            pVOEx->Draw(DVASPECT_CONTENT, -1, NULL, NULL, NULL, hDC,
                reinterpret_cast<RECTL*>(&m_rcPos),
                reinterpret_cast<RECTL*>(&m_rcPos), NULL, NULL);
            
            pVOEx->Release();
        }
        
        ::ReleaseDC(m_hWnd, hDC);
    }
    
    return S_OK;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::OnShowWindow()
// Desc: This window has no meaning since the control is in-place.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::OnShowWindow(BOOL)
{
    return S_OK;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::RequestNewObjectLayout()
// Desc: Not implemented.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::RequestNewObjectLayout()
{
    return E_NOTIMPL;
}

//////
// IParseDisplayName Methods

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::ParseDisplayName()
// Desc: Not implemented.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::ParseDisplayName(IBindCtx *, LPOLESTR, ULONG *, IMoniker **)
{
    return E_NOTIMPL;
}

//////
// IOleContainer Methods

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::EnumObjects()
// Desc: Not implemented.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::EnumObjects(DWORD, IEnumUnknown **)
{
    return E_NOTIMPL;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::LockContainer()
// Desc: Not implemented.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::LockContainer(BOOL)
{
    return E_NOTIMPL;
}

//////
// IControlSite Methods

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::OnControlInfoChanged()
// Desc: Not implemented.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::OnControlInfoChanged()
{
    return E_NOTIMPL;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::LockInPlaceActive()
// Desc: Not implemented.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::LockInPlaceActive(BOOL)
{
    return E_NOTIMPL;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::GetExtendedControl()
// Desc: Not implemented.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::GetExtendedControl(IDispatch **)
{
    return E_NOTIMPL;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::TransformCoords()
// Desc: Not implemented.
///////////////////////////////////////////////////////////////////////////////
HRESULT CMPContainer::TransformCoords(POINTL *, POINTF *, DWORD)
{
    return E_NOTIMPL;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CMPContainer::TranslateAccelerator()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -