Click here to Skip to main content
15,879,535 members
Articles / Desktop Programming / MFC

Using screensavers inside the Windows Media Player

Rate me:
Please Sign up or sign in to vote.
4.94/5 (12 votes)
15 Jul 2011CPOL1 min read 107.7K   3.1K   53  
Wrapping a screensaver inside a WMP visualization plug-in.
//------------------------------------------------------------------------------

#ifndef __SHEEPWMP_H_
#define __SHEEPWMP_H_

//------------------------------------------------------------------------------

#include "resource.h"
#include "effects.h"
#include "SheepWMP_h.h"

//------------------------------------------------------------------------------

class ATL_NO_VTABLE CSheepWMP : 
    public CComObjectRootEx<CComSingleThreadModel>,
    public CComCoClass<CSheepWMP, &CLSID_SheepWMP>,
    public IDispatchImpl<ISheepWMP, &IID_ISheepWMP, &LIBID_SHEEPWMPLib>,
    public IWMPEffects2
{
private:
    COLORREF    m_clrForeground;    // foreground color
    LONG        m_nPreset;          // current preset

    HRESULT WzToColor(const WCHAR *pwszColor, COLORREF *pcrColor);
    HRESULT ColorToWz( BSTR* pbstrColor, COLORREF crColor);
    DWORD SwapBytes(DWORD dwRet);

public:
    CSheepWMP();
    ~CSheepWMP();

DECLARE_REGISTRY_RESOURCEID(IDR_SHEEPWMP)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CSheepWMP)
    COM_INTERFACE_ENTRY(ISheepWMP)
    COM_INTERFACE_ENTRY(IDispatch)
    COM_INTERFACE_ENTRY(IWMPEffects)
    COM_INTERFACE_ENTRY(IWMPEffects2)
END_COM_MAP()

public:

    // CComCoClass Overrides
    HRESULT FinalConstruct();
    void FinalRelease();

    // ISheepWMP
    STDMETHOD(get_foregroundColor)(/*[out, retval]*/ BSTR *pVal);
    STDMETHOD(put_foregroundColor)(/*[in]*/ BSTR newVal);

    // IWMPEffects
    STDMETHOD(Render)(TimedLevel *pLevels, HDC hdc, RECT *rc);
    STDMETHOD(MediaInfo)(LONG lChannelCount, LONG lSampleRate, BSTR bstrTitle);
    STDMETHOD(GetCapabilities)(DWORD * pdwCapabilities);
    STDMETHOD(GoFullscreen)(BOOL fFullScreen) { return E_NOTIMPL; };
    STDMETHOD(RenderFullScreen)(TimedLevel *pLevels) { return E_NOTIMPL; };
    STDMETHOD(DisplayPropertyPage)(HWND hwndOwner) { return E_NOTIMPL; };
    STDMETHOD(GetTitle)(BSTR *bstrTitle);
    STDMETHOD(GetPresetTitle)(LONG nPreset, BSTR *bstrPresetTitle);
    STDMETHOD(GetPresetCount)(LONG *pnPresetCount);
    STDMETHOD(SetCurrentPreset)(LONG nPreset);
    STDMETHOD(GetCurrentPreset)(LONG *pnPreset);

    // IWMPEffects2
    STDMETHOD(SetCore)(IWMPCore * pCore);
    STDMETHOD(Create)(HWND hwndParent);
    STDMETHOD(Destroy)();
    STDMETHOD(NotifyNewMedia)(IWMPMedia *pMedia);
    STDMETHOD(OnWindowMessage)(UINT msg, WPARAM WParam, LPARAM LParam, LRESULT *plResultParam );
    STDMETHOD(RenderWindowed)(TimedLevel *pLevels, BOOL fRequiredRender );

private:
    void         ReleaseCore();

	CAtlString   GetScrName ( CAtlString aScr ) ;
	LPCTSTR      ActiveScr () ;
	HWND		 FindScreenSaverWnd ( HWND aParent ) ;

    HWND                        m_hwndParent;
    CComPtr<IWMPCore>           m_spCore;
	std::vector<CAtlString>     m_Scrs ;
};

//------------------------------------------------------------------------------

#endif //__SHEEPWMP_H_

//------------------------------------------------------------------------------

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Australia Australia
Developing windows applications for over 15 years now starting on Win 3.1 with Object Oriented Pascal, progressed to C++ and OWL, in 1996 switch to MFC and never looked back, now focusing on .NET/Mono.

Comments and Discussions