home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / addins / brkpntmgr / dlgsave.cpp < prev    next >
C/C++ Source or Header  |  1998-04-02  |  4KB  |  185 lines

  1. // DlgSave.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "resource.h"
  6. #include "DlgSave.h"
  7. #include <afxdlgs.h>
  8. #include "Brkpntmgr.h"
  9. #include "brkpnts.h"
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CDlgSave dialog
  19.  
  20.  
  21. CDlgSave::CDlgSave(CWnd* pParent /*=NULL*/)
  22.     : CSubDialog(CDlgSave::IDD, pParent)
  23. {
  24.     //{{AFX_DATA_INIT(CDlgSave)
  25.     m_fSaveOnlyEnabled = FALSE;
  26.     m_strFile = _T("");
  27.     m_fOutputWnd = FALSE;
  28.     m_strComment = _T("");
  29.     m_fOld = FALSE;
  30.     m_strStats = _T("");
  31.     //}}AFX_DATA_INIT
  32.  
  33. }
  34.  
  35. CDlgSave::~CDlgSave()
  36. {
  37. }
  38.  
  39.  
  40. BOOL CDlgSave::Create(CWnd *pParent)
  41. {
  42.     BOOL fOK;
  43.     fOK = CDialog::Create(IDD, pParent);
  44.     return(fOK);
  45. }
  46.  
  47. void CDlgSave::DoDataExchange(CDataExchange* pDX)
  48. {
  49.     CDialog::DoDataExchange(pDX);
  50.     //{{AFX_DATA_MAP(CDlgSave)
  51.     DDX_Check(pDX, IDC_CHECKSAVEONLYENABLED, m_fSaveOnlyEnabled);
  52.     DDX_Text(pDX, IDC_EDITFILE, m_strFile);
  53.     DDX_Text(pDX, IDC_EDITCOMMENT, m_strComment);
  54.     DDX_Text(pDX, IDC_STATS, m_strStats);
  55.     //}}AFX_DATA_MAP
  56. }
  57.  
  58.  
  59. BEGIN_MESSAGE_MAP(CDlgSave, CDialog)
  60.     //{{AFX_MSG_MAP(CDlgSave)
  61.     ON_BN_CLICKED(IDC_BUTTONBROWSE, OnButtonbrowse)
  62.     ON_BN_CLICKED(IDC_BUTTONLOAD, OnButtonload)
  63.     ON_BN_CLICKED(IDC_BUTTONCLEAR, OnButtonclear)
  64.     ON_BN_CLICKED(IDOK, OnOK)
  65.     ON_BN_CLICKED(IDC_BTNOUTPUTWND, OnBtnoutputwnd)
  66.     ON_WM_SHOWWINDOW()
  67.     ON_BN_CLICKED(ID_SAVE, OnSave)
  68.     //}}AFX_MSG_MAP
  69. END_MESSAGE_MAP()
  70.  
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CDlgSave message handlers
  73.  
  74. void CDlgSave::OnButtonbrowse() 
  75. {
  76.     CFileDialog dlgGetFile(FALSE, NULL, NULL, OFN_EXPLORER,
  77.         _T("brk files(*.brk)|*.brk|All Files (*.*)|*.*||"),
  78.         this);
  79.     
  80.     if (dlgGetFile.DoModal() == IDOK)
  81.     {
  82.         UpdateData();
  83.         m_strFile = dlgGetFile.GetPathName();
  84.         if (m_strFile.ReverseFind(_T('.')) == -1)
  85.         {
  86.             m_strFile += _T(".brk"); // add the missing extension
  87.         }
  88.  
  89.         UpdateData(FALSE);
  90.     }
  91. }
  92.  
  93. void CDlgSave::OnButtonload() 
  94. {
  95.     UpdateData(TRUE);
  96.     if (!m_strFile.IsEmpty() && m_pbrksmgr)
  97.     {
  98.         m_strComment.Empty();
  99.         m_pbrksmgr->Load(m_strFile, m_strComment, m_fOld);    
  100.         SetStats();
  101.         UpdateData(FALSE);
  102.     }
  103. }
  104.  
  105. BOOL CDlgSave::OnInitDialog() 
  106. {
  107.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  108.     CDialog::OnInitDialog();
  109.  
  110.     _ASSERTE(m_pbrksmgr);
  111.     SetStats();
  112.     return TRUE;  // return TRUE unless you set the focus to a control
  113.                   // EXCEPTION: OCX Property Pages should return FALSE
  114. }
  115.  
  116.  
  117. void CDlgSave::OnButtonclear() 
  118. {
  119.     if (m_pbrksmgr)
  120.     {
  121.         m_pbrksmgr->ClearAll();
  122.         SetStats(TRUE);
  123.     }    
  124. }
  125.  
  126. void CDlgSave::OnOK()
  127. {
  128.     CDialog::OnOK();
  129. }
  130.  
  131. void CDlgSave::OnSave() 
  132. {
  133.     UpdateData(TRUE);
  134.     if (!m_strFile.IsEmpty() && m_pbrksmgr)
  135.     {
  136.         m_pbrksmgr->Save(FALSE, m_strFile, m_fSaveOnlyEnabled, m_strComment);    
  137.     }
  138.     
  139. }
  140.  
  141. void CDlgSave::OnBtnoutputwnd() 
  142. {
  143.     UpdateData(TRUE);
  144.     if (m_pbrksmgr)
  145.     {
  146.         m_pbrksmgr->Save(TRUE, "\0", m_fSaveOnlyEnabled, m_strComment);    
  147.     }
  148.     
  149. }
  150.  
  151. void CDlgSave::SetStats(BOOL fUpdate /*= FALSE*/)
  152. {
  153.     long lTotal, lEnabled;
  154.     if (m_pbrksmgr)
  155.     {
  156.         m_pbrksmgr->GetCounts(lTotal, lEnabled);
  157.         if (lTotal > 0)
  158.         {
  159.             m_strStats.Format(_T("Total: %ld, Enabled: %ld"), lTotal, lEnabled);
  160.         }
  161.         else
  162.         {
  163.             m_strStats = _T("No Breakpoints Set");
  164.         }
  165.     }
  166.     else
  167.     {
  168.         m_strStats = _T("No Breakpoints Set");
  169.     }
  170.     if (fUpdate)
  171.     {
  172.         UpdateData(FALSE);
  173.     }
  174. }
  175.  
  176. void CDlgSave::OnShowWindow(BOOL bShow, UINT nStatus) 
  177. {
  178.     CDialog::OnShowWindow(bShow, nStatus);
  179.     
  180.     if (bShow)
  181.     {
  182.         SetStats(TRUE);
  183.     }
  184. }
  185.