Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

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

, 25 Oct 2002
A sample that can load, display, and print graphics files.
imgviewer.zip
Release
ImgViewer.exe
res
ImgViewer.ico
ImgViewerDoc.ico
Toolbar.bmp
ImgViewer.clw
ImgViewer.dsp
ImgViewer.dsw
// 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__;
#endif


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;
	}
	else
	{
		return FALSE;
	}
}

CDocTemplate::Confidence CMultiExtSDTemplate::MatchDocType(LPCTSTR lpszPathName,
														   CDocument *&rpDocMatch)
{
	ASSERT(::AfxIsValidString(lpszPathName));

	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.IsEmpty())
	{
		strMultiFilterExt.Replace(_T(";*"), _T(";"));

        CString strFilterExt;
        for (int i = 0;
			 ::AfxExtractSubString(strFilterExt, strMultiFilterExt, i, _T(';'));
			 i++)
        {
		    // 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.

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

Share

About the Author

Chen Su
Software Developer
Canada Canada
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.141022.2 | Last Updated 26 Oct 2002
Article Copyright 2002 by Chen Su
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid