Click here to Skip to main content
13,597,272 members
Click here to Skip to main content


55 bookmarked
Posted 25 Oct 2002

An Image (GIF, JPEG, BMP, ICO, WMF and EMF) Viewer

, 25 Oct 2002
A sample that can load, display, and print graphics files.
// MulExtDocTmp.cpp
// Microsoft KB Articles:
// Q141921 - HOWTO: How to Support Two File Extensions per MFC Document Type
// Q198538 - DocMgrEx.exe Assoc Multiple File Extensions w/1 Doc Type

#include "stdafx.h"
#include <..\src\afximpl.h>		// AfxComparePath
#include "MulExtDocTmp.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;

BOOL CMultiExtSDTemplate::GetDocString(CString &rString,
									   enum DocStringIndex i) const
	if (::AfxExtractSubString(rString, m_strDocStrings, static_cast<int>(i)))
		if (i == CDocTemplate::filterExt)
			rString.Replace(_T(";"), _T(";*"));
		return TRUE;
		return FALSE;

CDocTemplate::Confidence CMultiExtSDTemplate::MatchDocType(LPCTSTR lpszPathName,
														   CDocument *&rpDocMatch)

	rpDocMatch = NULL;

	// go through all documents
	POSITION pos = this->GetFirstDocPosition();
	while (pos != NULL)
		CDocument *const pDoc = this->GetNextDoc(pos);
		if (::AfxComparePath(pDoc->GetPathName(), lpszPathName))
			// already open
			rpDocMatch = pDoc;
            return yesAlreadyOpen;

    // deal with multiple extensions in the template filter
	// see if it matches our default suffix
	CString strMultiFilterExt;
	if (this->GetDocString(strMultiFilterExt, CDocTemplate::filterExt) &&
		strMultiFilterExt.Replace(_T(";*"), _T(";"));

        CString strFilterExt;
        for (int i = 0;
			 ::AfxExtractSubString(strFilterExt, strMultiFilterExt, i, _T(';'));
		    // see if extension matches
		    ASSERT(strFilterExt[0] == _T('.'));

			const LPCTSTR lpszDot = ::_tcsrchr(lpszPathName, _T('.'));
			if (lpszDot != NULL && ::lstrcmpi(lpszDot, strFilterExt) == 0)
                return yesAttemptNative; // extension matches, looks like ours

	// otherwise we will guess it may work
	return yesAttemptForeign;

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.


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


About the Author

Chen Su
Software Developer
Canada Canada
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.180621.3 | Last Updated 26 Oct 2002
Article Copyright 2002 by Chen Su
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid