home *** CD-ROM | disk | FTP | other *** search
/ Mastering Computers 3 / Mastering Computers Vol 3.iso / Win95 / Fun&Utils / MFCMSG.EXE / DOC.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-01  |  1.1 KB  |  47 lines

  1. #include "stdafx.h" 
  2. #include "cmdlearn.h"
  3. #include "doc.h"
  4.  
  5. IMPLEMENT_DYNCREATE(CFileDoc, CDocument)
  6.  
  7. BEGIN_MESSAGE_MAP(CFileDoc, CDocument)
  8.    //{{AFX_MSG_MAP(CFileDoc)
  9.    ON_COMMAND(ID_UPDATE_STATUS, OnUpdateStatus)
  10.    //}}AFX_MSG_MAP
  11. END_MESSAGE_MAP()
  12.  
  13. CFileDoc::CFileDoc()
  14. {
  15. }
  16.  
  17. CFileDoc::~CFileDoc()
  18. {
  19. }
  20.  
  21. //////////////////
  22. // Open document: read status information.
  23. //
  24. BOOL CFileDoc::OnOpenDocument(const char* pszPathName)
  25. {
  26.    CFile file;
  27.    return file.Open(pszPathName, CFile::modeRead) ?
  28.       file.GetStatus(m_status) : FALSE;
  29. }
  30.  
  31. //////////////////
  32. // "Update status" command: 
  33. // Re-open the doc. If changed or can't open, inform all views. 
  34. // This command is sent by the frame when the timer goes off.
  35. //
  36. void CFileDoc::OnUpdateStatus()
  37. {
  38.    CFileStatus old = m_status;
  39.    if (!OnOpenDocument(GetPathName())) 
  40.    {
  41.       // Couldn't open file (it was deleted): close all views
  42.       UpdateAllViews(NULL, ID_FILE_CLOSE);
  43.  
  44.    } else if (memcmp(&m_status, &old, sizeof(old) - _MAX_PATH) != 0)
  45.       UpdateAllViews(NULL);
  46. }
  47.