本文整理汇总了C++中CDocTemplate::MatchDocType方法的典型用法代码示例。如果您正苦于以下问题:C++ CDocTemplate::MatchDocType方法的具体用法?C++ CDocTemplate::MatchDocType怎么用?C++ CDocTemplate::MatchDocType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDocTemplate
的用法示例。
在下文中一共展示了CDocTemplate::MatchDocType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
CDocument *CDocManager::OpenDocumentFile( LPCTSTR lpszFileName )
/**************************************************************/
{
POSITION position = m_templateList.GetHeadPosition();
CDocTemplate *pSelected = NULL;
CDocTemplate::Confidence nSelConfidence = CDocTemplate::noAttempt;
while( position != NULL ) {
CDocTemplate *pTemplate = (CDocTemplate *)m_templateList.GetNext( position );
ASSERT( pTemplate != NULL );
CDocument *pMatch = NULL;
CDocTemplate::Confidence nConfidence = pTemplate->MatchDocType( lpszFileName,
pMatch );
if( nConfidence > nSelConfidence ) {
nSelConfidence = nConfidence;
pSelected = pTemplate;
if( nConfidence == CDocTemplate::yesAlreadyOpen ) {
ASSERT( pMatch != NULL );
POSITION viewPos = pMatch->GetFirstViewPosition();
if( viewPos != NULL ) {
CView *pView = pMatch->GetNextView( viewPos );
CFrameWnd *pFrame = pView->GetParentFrame();
ASSERT( pFrame != NULL );
pFrame->ActivateFrame();
}
return( pMatch );
}
}
}
if( pSelected == NULL ) {
return( NULL );
}
return( pSelected->OpenDocumentFile( lpszFileName ) );
}
示例2: CanOpenDocument
//////////////////
// This helper fn determines if I can open a document. It searches the doc
// templates for one whose file name extension matches the requested file.
// (copied from an article of MSJ magazine)
CDocTemplate* CExtractImageApp::CanOpenDocument(LPCTSTR lpszPath)
{
CDocument* pDoc=NULL;
POSITION pos = m_pDocManager->GetFirstDocTemplatePosition();
while (pos != NULL) {
CDocTemplate* pdt = m_pDocManager->GetNextDocTemplate(pos);
if (pdt->MatchDocType(lpszPath,pDoc) >= CDocTemplate::yesAttemptNative)
return pdt;
}
if (!pDoc) {
// If you got here, you may have forgotten to set the string(s)
// describing your document types
//CString sErr; sErr.Format("***Can't find doc template for %s\n", lpszPath);
//AfxMessageBox(sErr);
}
return NULL;
}
示例3: SearchDocument
CDocument* COXChildFrameState::SearchDocument(LPCTSTR pszDocPath)
// --- In : pszDocPath : File path of a document
// --- Out :
// --- Returns : The open document with that file path or NULL otherwise
// --- Effect :
{
if (pszDocPath == NULL)
// ... Can only search for documents with a non-empty name
return NULL;
CDocument* pDoc = NULL;
POSITION templatePos = NULL;
CDocTemplate* pDocTemplate = NULL;
templatePos = AfxGetApp()->GetFirstDocTemplatePosition();
while((pDoc == NULL) && (templatePos != NULL))
{
pDocTemplate = AfxGetApp()->GetNextDocTemplate(templatePos);
ASSERT(pDocTemplate != NULL);
if (pDocTemplate->MatchDocType(pszDocPath, pDoc) != CDocTemplate::yesAlreadyOpen)
pDoc = NULL;
}
return pDoc;
}
示例4: OpenDocumentFile
CDocument* CMyDocManager::OpenDocumentFile(LPCTSTR lpszFileName)
{
// From MFC: CDocManager::OpenDocumentFile
CString strFileName = lpszFileName;
strFileName.TrimLeft();
strFileName.TrimRight();
if (strFileName[0] == '\"')
strFileName.Delete(0);
int nPos = strFileName.ReverseFind('\"');
if (nPos != -1)
strFileName.Delete(nPos);
CString strQuery, strPage;
nPos = strFileName.Find('?');
if (nPos != -1)
{
strQuery = strFileName.Mid(nPos + 1);
strFileName = strFileName.Left(nPos);
}
bool bPathTooLong = false;
TCHAR szPath[_MAX_PATH];
if (!AfxFullPath(szPath, strFileName))
bPathTooLong = true;
if (bPathTooLong || !PathFileExists(szPath))
{
// Try extracting page number
nPos = strFileName.ReverseFind('#');
if (nPos != -1)
{
strPage = strFileName.Mid(nPos + 1);
strFileName = strFileName.Left(nPos);
if (!AfxFullPath(szPath, strFileName))
bPathTooLong = true;
}
}
if (bPathTooLong)
{
AfxMessageBox(FormatString(IDS_PATH_TOO_LONG, szPath), MB_ICONEXCLAMATION | MB_OK);
return NULL;
}
TCHAR szLinkName[_MAX_PATH];
if (AfxResolveShortcut(GetMainWnd(), szPath, szLinkName, _MAX_PATH))
lstrcpy(szPath, szLinkName);
// find the highest confidence
CDocTemplate::Confidence bestMatch = CDocTemplate::noAttempt;
CDocTemplate* pBestTemplate = NULL;
CDocument* pOpenDocument = NULL;
CMainFrame* pOldMainFrm = (CMainFrame*) theApp.m_pMainWnd;
POSITION pos = m_templateList.GetHeadPosition();
while (pos != NULL)
{
CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetNext(pos);
ASSERT_KINDOF(CDocTemplate, pTemplate);
CDocTemplate::Confidence match;
ASSERT(pOpenDocument == NULL);
match = pTemplate->MatchDocType(szPath, pOpenDocument);
if (match > bestMatch)
{
bestMatch = match;
pBestTemplate = pTemplate;
}
if (match == CDocTemplate::yesAlreadyOpen)
break;
}
if (pOpenDocument != NULL)
{
POSITION pos = pOpenDocument->GetFirstViewPosition();
if (pos != NULL)
{
CView* pView = pOpenDocument->GetNextView(pos);
ASSERT_VALID(pView);
CMainFrame* pMainFrm = (CMainFrame*) pView->GetTopLevelFrame();
pMainFrm->ActivateDocument(pOpenDocument);
}
else
TRACE(_T("Error: Can not find a view for document to activate.\n"));
}
if (pOpenDocument == NULL)
{
if (pBestTemplate == NULL)
{
AfxMessageBox(AFX_IDP_FAILED_TO_OPEN_DOC);
return NULL;
}
pOpenDocument = pBestTemplate->OpenDocumentFile(szPath);
}
//.........这里部分代码省略.........