Click here to Skip to main content
12,350,334 members (27,278 online)
Click here to Skip to main content

Stats

243.8K views
6.4K downloads
54 bookmarked
Posted

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__;
#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

You may also be interested in...

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