Click here to Skip to main content
15,885,914 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 139.8K   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 "updateregistry.h"
#include "catchhandler.h"
#include "queryinfoimpl.h"
#include "shelluuids.h"


namespace MSF
{

template <typename T>
class ATL_NO_VTABLE IInfoTipImpl :
	public IPersistFile,
	public IQueryInfoImpl
{
public:
	// Registration function to register the infotip 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);
	}


	// Registration function to register the COM object + the root extension.
	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);
	}


	// Registration function to register the extension based on the root extension.
	static HRESULT WINAPI UpdateRegistryForExt(UINT nResId, BOOL bRegister,
		const wchar_t* szRootType, const wchar_t* szExtension) throw()
	{
		return ::UpdateRegistryForExt(nResId, bRegister,
			szRootType, szExtension);
	}


	// All-in-one registration function for 1 extenstion, call 'ForExt' to register
	// aditional functions.
	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);
	}


	// IPersistFile
	// Note: A lot of functions are defined by the interface, but not for infotip objects.
	STDMETHOD(GetClassID)(LPCLSID)
	{
		ATLTRACENOTIMPL(_T("IInfoTipImpl::GetClassID"));
	}


	STDMETHOD(IsDirty)()
	{
		ATLTRACENOTIMPL(_T("IInfoTipImpl::IsDirty"));
	}


	STDMETHOD(Save)(LPCOLESTR, BOOL)
	{
		ATLTRACENOTIMPL(_T("IInfoTipImpl::Save"));
	}


	STDMETHOD(SaveCompleted)(LPCOLESTR)
	{
		ATLTRACENOTIMPL(_T("IInfoTipImpl::SaveCompleted"));
	}


	STDMETHOD(GetCurFile)(LPOLESTR*)
	{
		ATLTRACENOTIMPL(_T("IInfoTipImpl::GetCurFile"));
	}


	STDMETHOD(Load)(LPCOLESTR wszFilename, DWORD dwMode)
	{
		(dwMode); // unused in release.

#ifdef UNICODE
		ATLTRACE2(atlTraceCOM, 0, L"IInfoTipImpl::Load (instance=%p, mode=%d, filename=%s)\n", this, dwMode, wszFilename);
#else
		ATLTRACE2(atlTraceCOM, 0, "IInfoTipImpl::Load (instance=%p, mode=%d, , filename=%S)\n", this, dwMode, wszFilename);
#endif

		try
		{
			// Note: CreateInfoTipText must be implemented by the derived class.
			SetInfoTipText(static_cast<T*>(this)->CreateInfoTipText(CW2T(wszFilename)));
			return S_OK;
		}
		MSF_COM_CATCH_HANDLER()
	}
};

} // 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