Click here to Skip to main content
15,897,518 members
Articles / Desktop Programming / MFC

Create Thumbnail Extractor Objects for Your MFC Document Types

Rate me:
Please Sign up or sign in to vote.
4.94/5 (23 votes)
21 Nov 20025 min read 356.8K   4.3K   104  
An article on writing thumbnail shell extensions for your MFC document types
// ThumbWizaw.cpp : implementation file
//

#include "stdafx.h"
#include "ThumbWiz.h"
#include "ThumbWizaw.h"
#include "Chooser.h"
#include <atlbase.h> 
#include <ObjModel\bldauto.h>

#ifdef _PSEUDO_DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

// This is called immediately after the custom AppWizard is loaded.  Initialize
//  the state of the custom AppWizard here.
void CThumbWizAppWiz::InitCustomAppWiz()
{
	// Add build step to .hpj if there is one
	m_Dictionary[_T("HELP")] = _T("1");

	// Inform AppWizard that we're making a DLL.
	m_Dictionary[_T("PROJTYPE_DLL")] = _T("1");

	// Create a new dialog chooser; CDialogChooser's constructor initializes
	//  its internal array with pointers to the steps.
	m_pChooser = new CDialogChooser;

	// Set the maximum number of steps.
	SetNumberOfSteps(LAST_DLG);
}

// This is called just before the custom AppWizard is unloaded.
void CThumbWizAppWiz::ExitCustomAppWiz()
{
	// Deallocate memory used for the dialog chooser
	ASSERT(m_pChooser != NULL);
	delete m_pChooser;
	m_pChooser = NULL;
}

// This is called when the user clicks "Create..." on the New Project dialog
CAppWizStepDlg* CThumbWizAppWiz::Next(CAppWizStepDlg* pDlg)
{
	// Get value of $$root$$ (already set by AppWizard)
	CString strRoot;
	m_Dictionary.Lookup(_T("Root"), strRoot);
	
	// Set value of $$Doc$$, $$DOC$$
	CString strDoc = strRoot.Left(6);
	m_Dictionary[_T("Doc")] = strDoc;
	strDoc.MakeUpper();
	m_Dictionary[_T("DOC")] = strDoc;

	// Set value of $$MAC_TYPE$$
	strRoot = strRoot.Left(4);
	int nLen = strRoot.GetLength();
	if (strRoot.GetLength() < 4)
	{
		CString strPad(_T(' '), 4 - nLen);
		strRoot += strPad;
	}
	strRoot.MakeUpper();
	m_Dictionary[_T("MAC_TYPE")] = strRoot;

	// create GUIDs
	m_Dictionary[_T("CLSID")] = CreateNewStringGuid();
	m_Dictionary[_T("IID")] = CreateNewStringGuid();
	m_Dictionary[_T("LIBID")] = CreateNewStringGuid();


	// Delegate to the dialog chooser
	return m_pChooser->Next(pDlg);
}

CString CThumbWizAppWiz::CreateNewStringGuid()
{
	GUID guid; CComBSTR bstrGuid; CString sGuid;
	::CoCreateGuid(&guid);
	::StringFromCLSID(guid,&bstrGuid);
	sGuid = bstrGuid;
	// remove { and }
	sGuid = sGuid.Mid(1,sGuid.GetLength()-2); 
	return sGuid;
}

void CThumbWizAppWiz::CustomizeProject(IBuildProject* pProject)
{
	// TODO: Add code here to customize the project.  If you don't wish
	//  to customize project, you may remove this virtual override.
	
	// This is called immediately after the default Debug and Release
	//  configurations have been created for each platform.  You may customize
	//  existing configurations on this project by using the methods
	//  of IBuildProject and IConfiguration such as AddToolSettings,
	//  RemoveToolSettings, and AddCustomBuildStep. These are documented in
	//  the Developer Studio object model documentation.

	// WARNING!!  IBuildProject and all interfaces you can get from it are OLE
	//  COM interfaces.  You must be careful to release all new interfaces
	//  you acquire.  In accordance with the standard rules of COM, you must
	//  NOT release pProject, unless you explicitly AddRef it, since pProject
	//  is passed as an "in" parameter to this function.  See the documentation
	//  on CCustomAppWiz::CustomizeProject for more information.
	CComPtr<IConfiguration> pConfiguration;
	CComPtr<IConfigurations> pConfigurations;
	long i,nConfigs; CComVariant vtReserved;

	CString sObject,sIdl,sMIDLset,sRoot;
	m_Dictionary.Lookup(_T("Object"),sObject);
	m_Dictionary.Lookup(_T("Root"),sRoot);
	pProject->get_Configurations(&pConfigurations);
	pConfigurations->get_Count(&nConfigs);
	for(i=1; i<=nConfigs; i++) {
		pConfigurations->Item(CComVariant(i),&pConfiguration);
#if _DEBUG
		CComBSTR strConfName; CString sConfName;
		pConfiguration->get_Name(&strConfName);
		sConfName = strConfName;
		TRACE("Current configuration: %s\n",sConfName);
#endif
		TRACE("Adding custom build step\n");
		// add a custom build step for to registrate the component
		pConfiguration->AddCustomBuildStep(
			CComBSTR("regsvr32 /s /c \"$(TargetPath)\" \n"
			"echo regsvr32 exec. time > \"$(OutDir)\\regsvr32.trg\""),
			CComBSTR("$(OutDir)\\regsvr32.trg"),
			CComBSTR("Performing Registration on $(InputPath)"),vtReserved);
		// MIDL settings are old, make them ATL compatible
		sIdl.Format("Thumb%s.idl",sObject);
		TRACE("RemoveFileSettings for %s\n",sRoot);
		pConfiguration->RemoveToolSettings (CComBSTR("midl.exe"),
			CComBSTR("/nologo /mktyplib203"),vtReserved);
		sMIDLset.Format("/tlb \"./Thumb%s.tlb\" /h \"Thumb%s_i.h\" /iid \"Thumb%s_i.c\" /Oicf",
			sObject,sObject,sObject);
		TRACE("AddFileSettings for %s\n",sIdl);
		pConfiguration->AddFileSettings(CComBSTR(sIdl),
			CComBSTR(sMIDLset),vtReserved);
		}
}


// Here we define one instance of the CThumbWizAppWiz class.  You can access
//  m_Dictionary and any other public members of this class through the
//  global ThumbWizaw.
CThumbWizAppWiz ThumbWizaw;


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.


Written By
Web Developer Forthnet
Greece Greece
Software developer and Microsoft Trainer, Athens, Greece (MCT, MCSD.net, MCSE 2003, MCDBA 2000,MCTS, MCITP, MCIPD).

Comments and Discussions