Click here to Skip to main content
15,895,142 members
Articles / Desktop Programming / ATL

The Mini Shell Extension Framework – Part III

Rate me:
Please Sign up or sign in to vote.
4.96/5 (11 votes)
18 Sep 200516 min read 142.2K   1.4K   46  
Discussion of a small C++ framework to create Windows shell extensions (IShellFolderImpl).
//
// (C) Copyright by Victor Derks <vba64@xs4all.nl>
//
// See README.TXT for the details of the software licence.
//
#pragma once


#include <vector>
#include <algorithm>
#include "updateregistry.h"
#include "shellextinitimpl.h"
#include "catchhandler.h"


#pragma comment(lib, "comctl32")


namespace MSF
{

template <typename T>
class ATL_NO_VTABLE IShellPropSheetExtImpl :
	public IShellExtInitImpl,
	public IShellPropSheetExt
{
public:
	// Registration function to register with a common shellfolder.
	static HRESULT WINAPI UpdateRegistry(UINT nResId, BOOL bRegister,
		const wchar_t* szDescription, const CLSID& clsidShellFolder, const wchar_t* szExtension) throw()
	{
		return UpdateRegistryFromResource(nResId, bRegister,
			szDescription, T::GetObjectCLSID(), clsidShellFolder, szExtension);
	}


	static HRESULT WINAPI UpdateRegistryForRootExt(UINT nResId, BOOL bRegister,
		const wchar_t* szDescription, const wchar_t* szRootExt) throw()
	{
		return ::UpdateRegistryForRootExt(nResId, bRegister,
			szDescription, T::GetObjectCLSID(), szRootExt);
	}


	static HRESULT WINAPI UpdateRegistryForExt(UINT nResId, BOOL bRegister,
		const wchar_t* szRootExt, const wchar_t* szExtension) throw()
	{
		return ::UpdateRegistryForExt(nResId, bRegister,
			szRootExt, szExtension);
	}


	static HRESULT WINAPI UpdateRegistry(UINT nResIdRoot, UINT nResIdExt, BOOL bRegister,
		const wchar_t* szDescription, const wchar_t* szRootExt, const wchar_t* szExtension) throw()
	{
		return ::UpdateRegistry(nResIdRoot, nResIdExt, bRegister,
			szDescription, T::GetObjectCLSID(), szRootExt, szExtension);
	}


	IShellPropSheetExtImpl()
	{
		ATLTRACE2(atlTraceCOM, 0, _T("IShellPropSheetExtImpl::Constructor (instance=%p)\n"), this);
	}


	~IShellPropSheetExtImpl()
	{
		ATLTRACE2(atlTraceCOM, 0, _T("IShellPropSheetExtImpl::~Destructor (instance=%p)\n"), this);
	}


	class CAddPage
	{
	public:
		CAddPage(LPFNSVADDPROPSHEETPAGE pfnAddPage, LPARAM lParam) :
			m_pfnAddPage(pfnAddPage),
			m_lParam(lParam)
		{
		}


		void operator()(HPROPSHEETPAGE hPage) const
		{
			if (!m_pfnAddPage(hPage, m_lParam))
			{
				ATLVERIFY(::DestroyPropertySheetPage(hPage));
				RaiseException(E_FAIL);
			}
		}

	private:

		// Member variables.
		LPFNSVADDPROPSHEETPAGE m_pfnAddPage;
		LPARAM                 m_lParam;
	};


	// IShellPropSheetExt
	STDMETHOD(AddPages)(LPFNSVADDPROPSHEETPAGE pfnAddPage, LPARAM lParam)
	{
		try
		{
			CAddPage addpage(pfnAddPage, lParam);

			static_cast<T*>(this)->OnAddPages(addpage, GetFilenames());
			return S_OK;
		}
		MSF_COM_CATCH_HANDLER()
	}


	STDMETHOD(ReplacePage)(EXPPS /*uPageID*/, LPFNSVADDPROPSHEETPAGE /*pfnReplaceWith*/, LPARAM /*lParam*/)
	{
		// The Shell doesn't call this function for file class Property Sheets.
		// Only for control panel objects.
		ATLTRACENOTIMPL(_T("CPropSheetExtImpl::ReplacePage"));
	}

protected:

	// OnAddPages must be implemented by derived classes.
	void OnAddPages(const CAddPage& /*addpages*/, const CStrings& /*filenames*/);
};

} // namespace MSF

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior) Hitachi High-Tech Analytical Science
Netherlands Netherlands
Victor lives in Nijmegen, the oldest city in The Netherlands.
He studied Applied Physics in Delft and works Hitachi High-Tech Analytical Science.

Comments and Discussions