home *** CD-ROM | disk | FTP | other *** search
/ Master Visual C++ 1.5 / MASTERVC15.ISO / vcprog / original / ch15 / arch / archview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-22  |  2.4 KB  |  119 lines

  1. // archview.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "arch.h"
  6. #include "archview.h"
  7.  
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char BASED_CODE THIS_FILE[] = __FILE__;
  11. #endif
  12.  
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CArchView
  15.  
  16. IMPLEMENT_DYNCREATE(CArchView, CFormView)
  17.  
  18. CArchView::CArchView()
  19.     : CFormView(CArchView::IDD)
  20. {
  21.     //{{AFX_DATA_INIT(CArchView)
  22.     m_Var1 = "";
  23.     m_Var2 = "";
  24.     //}}AFX_DATA_INIT
  25. }
  26.  
  27. CArchView::~CArchView()
  28. {
  29. }
  30.  
  31. void CArchView::DoDataExchange(CDataExchange* pDX)
  32. {
  33.     CFormView::DoDataExchange(pDX);
  34.     //{{AFX_DATA_MAP(CArchView)
  35.     DDX_Text(pDX, IDC_VAR1, m_Var1);
  36.     DDX_Text(pDX, IDC_VAR2, m_Var2);
  37.     //}}AFX_DATA_MAP
  38. }
  39.  
  40.  
  41. BEGIN_MESSAGE_MAP(CArchView, CFormView)
  42.     //{{AFX_MSG_MAP(CArchView)
  43.     ON_BN_CLICKED(IDC_SAVE_BUTTON, OnSaveButton)
  44.     ON_BN_CLICKED(IDC_LOAD_BUTTON, OnLoadButton)
  45.     //}}AFX_MSG_MAP
  46. END_MESSAGE_MAP()
  47.  
  48.  
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CArchView message handlers
  51.  
  52.  
  53. void CArchView::OnSaveButton()
  54. {
  55.     // TODO: Add your control notification handler code here
  56.  
  57.   //////////////////////
  58.   // MY CODE STARTS HERE
  59.   //////////////////////
  60.  
  61.   // Update m_Var1 and m_Var2 with the screen contents.
  62.   UpdateData(TRUE);
  63.  
  64.   // Create the file TRY.TRY.
  65.   CFile f;
  66.   f.Open("TRY.TRY", CFile::modeCreate | CFile::modeWrite );
  67.  
  68.   // Create an archive object.
  69.   CArchive ar( &f, CArchive::store );
  70.  
  71.   // Serialize m_Var1 and m_Var2 into the archive.
  72.   ar << m_Var1 << m_Var2;
  73.  
  74.   // Close the archive
  75.   ar.Close();
  76.  
  77.   // Close the file.
  78.   f.Close();
  79.  
  80.   ////////////////////
  81.   // MY CODE ENDS HERE
  82.   ////////////////////
  83.     
  84. }
  85.  
  86. void CArchView::OnLoadButton()
  87. {
  88.     // TODO: Add your control notification handler code here
  89.     
  90.   ///////////////////////
  91.   // MY CODE STARTS HERE
  92.   //////////////////////
  93.  
  94.   // Open the file TRY.TRY.
  95.   CFile f;
  96.   if ( f.Open("TRY.TRY", CFile::modeRead)== FALSE )
  97.      return;
  98.  
  99.   // Create an archive object.
  100.   CArchive ar( &f, CArchive::load );
  101.  
  102.   // Serialize data from the archive into m_Var1 and m_Var2.
  103.   ar >> m_Var1 >> m_Var2;
  104.  
  105.   // Close the archive
  106.   ar.Close();
  107.  
  108.   // Close the file.
  109.   f.Close();
  110.  
  111.   // Update screen with the new values of m_Var1 and m_Var2.
  112.   UpdateData(FALSE);
  113.  
  114.   ////////////////////
  115.   // MY CODE ENDS HERE
  116.   ////////////////////
  117.  
  118. }
  119.