home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / FILE_LK.ZIP / FILELDOC.CPP < prev    next >
C/C++ Source or Header  |  1993-12-18  |  3KB  |  143 lines

  1. // fileldoc.cpp : implementation of the CFilelookDoc class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "filelook.h"
  6.  
  7. #include "fileldoc.h"
  8.  
  9. #ifdef _DEBUG
  10. #undef THIS_FILE
  11. static char BASED_CODE THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CFilelookDoc
  16.  
  17. IMPLEMENT_DYNCREATE(CFilelookDoc, CDocument)
  18.  
  19. BEGIN_MESSAGE_MAP(CFilelookDoc, CDocument)
  20.     //{{AFX_MSG_MAP(CFilelookDoc)
  21.     //}}AFX_MSG_MAP
  22. END_MESSAGE_MAP()
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CFilelookDoc construction/destruction
  26.  
  27. CFilelookDoc::CFilelookDoc()
  28. {
  29.     // TODO: add one-time construction code here
  30.     m_pMyFile = NULL;
  31. }
  32.  
  33. CFilelookDoc::~CFilelookDoc()
  34. {
  35. }
  36.  
  37.  
  38. void CFilelookDoc::DeleteContents()
  39. {
  40.     if (m_pMyFile != NULL)
  41.     {
  42.         m_pMyFile->Close();
  43.         delete m_pMyFile;
  44.         m_pMyFile=NULL;
  45.         SetTitle("No file");
  46.     }
  47. }
  48.  
  49.  
  50.  
  51. BOOL CFilelookDoc::OnNewDocument()
  52. {
  53.     if (!CDocument::OnNewDocument())
  54.         return FALSE;
  55.     // TODO: add reinitialization code here
  56.     // (SDI documents will reuse this document)
  57.     return TRUE;
  58. }
  59.  
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CFilelookDoc serialization
  62.  
  63. void CFilelookDoc::Serialize(CArchive& ar)
  64. {
  65.     if (ar.IsStoring())
  66.     {
  67.         // TODO: add storing code here
  68.     }
  69.     else
  70.     {
  71.         // TODO: add loading code here
  72.     }
  73. }
  74.  
  75.  
  76. /////////////////////////////////////////////////////////////////////////////
  77. // CFilelookDoc diagnostics
  78.  
  79. #ifdef _DEBUG
  80. void CFilelookDoc::AssertValid() const
  81. {
  82.     CDocument::AssertValid();
  83. }
  84.  
  85. void CFilelookDoc::Dump(CDumpContext& dc) const
  86. {
  87.     CDocument::Dump(dc);
  88. }
  89.  
  90. #endif //_DEBUG
  91.  
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CFilelookDoc commands
  94.  
  95. BOOL CFilelookDoc::OnOpenDocument(const char* pszPathName)
  96. {
  97.     // TODO: Add your command handler code here
  98.     CString strFileTitle;
  99.  
  100.     //
  101.     // First close any open file
  102.     //
  103.  
  104.     if ( m_pMyFile != NULL )
  105.     {
  106.         m_pMyFile->Close();
  107.         delete m_pMyFile;
  108.         m_pMyFile = NULL;
  109.         SetTitle("No file");
  110.          UpdateAllViews(NULL);
  111.     }
  112.  
  113.     TRY
  114.     {
  115.             //
  116.             // try to open the file here
  117.             //
  118.             m_pMyFile = new CLineFile( pszPathName,
  119.                                         CFile::modeRead | CFile::typeBinary);
  120.             m_lFileSize = m_pMyFile->GetLength();
  121.             if (m_lFileSize ==0){
  122.               m_pMyFile->Close();
  123.               delete m_pMyFile;
  124.               m_pMyFile = NULL;
  125.               return 0;
  126.             }
  127.  
  128.             m_pMyFile->SeekToBegin();
  129.  
  130.             SetTitle( pszPathName );
  131.             UpdateAllViews(NULL);
  132.     }
  133.     CATCH( CFileException, e )
  134.     {
  135.         char ErrorMsg[ 80 ];
  136.         sprintf( ErrorMsg,"Error!\nOpening %s returned a 0x%lx.",
  137.                 (const char*)strFileTitle, e->m_lOsError );
  138.         AfxMessageBox( ErrorMsg );
  139.     }
  140.     END_CATCH
  141.     return TRUE;    
  142. }
  143.