|
// 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.
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
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.