简体   繁体   English

MFC 的 CDocument::ReleaseFile 示例

[英]Example of CDocument::ReleaseFile for MFC

How can I use CDocument::ReleaseFile in MFC?如何在 MFC 中使用CDocument::ReleaseFile

In the Microsoft Docs there's only the member function, but not an example.在 Microsoft Docs 中只有成员 function,但不是示例。

Create Thumbnail Extractor Objects for Your MFC Document Types 为您的 MFC 文档类型创建缩略图提取器对象

 // load content of file, code taken from MFC OnOpenDocument and modified
 CFileException fe;
 CFile* pFile = m_pDoc->GetFile(sFileName,    CFile::modeRead, &fe);
 if (pFile == NULL)
     return FALSE;

 m_pDoc->DeleteContents();
 CArchive loadArchive(pFile, CArchive::load | CArchive::bNoFlushOnDelete);
 loadArchive.m_pDocument = m_pDoc;
 loadArchive.m_bForceFlat = FALSE;
 try
 {
     if (pFile->GetLength() != 0)
         m_pDoc->Serialize(loadArchive);     // load me
     loadArchive.Close();
     m_pDoc->ReleaseFile(pFile, FALSE);
 }
 catch(CException *e)
 {
     //e->ReportError();
     m_pDoc->ReleaseFile(pFile, TRUE);
     m_pDoc->DeleteContents();   // remove failed contents
     e->Delete();
     return FALSE;
 }
 return TRUE;
 //delete pDoc;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM