home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / samples / c12 / clock / alarmppg.cpp next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  4.5 KB  |  147 lines

  1. // AlarmPropPage.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Clock.h"
  6. #include "AlarmPpg.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CAlarmPropPage dialog
  16.  
  17. IMPLEMENT_DYNCREATE(CAlarmPropPage, COlePropertyPage)
  18.  
  19.  
  20. /////////////////////////////////////////////////////////////////////////////
  21. // Message map
  22.  
  23. BEGIN_MESSAGE_MAP(CAlarmPropPage, COlePropertyPage)
  24.     //{{AFX_MSG_MAP(CAlarmPropPage)
  25.     ON_BN_CLICKED(IDC_FILE_SELECT, OnSoundFileSelect)
  26.     //}}AFX_MSG_MAP
  27. END_MESSAGE_MAP()
  28.  
  29.  
  30. /////////////////////////////////////////////////////////////////////////////
  31. // Initialize class factory and guid
  32.  
  33. // {FAF0BF81-27D6-11CF-A151-00AA00374DD8}
  34. IMPLEMENT_OLECREATE_EX(CAlarmPropPage, "Clock.CAlarmPropPage",
  35.     0xfaf0bf81, 0x27d6, 0x11cf, 0xa1, 0x51, 0x0, 0xaa, 0x0, 0x37, 0x4d, 0xd8)
  36.  
  37.  
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CAlarmPropPage::CAlarmPropPageFactory::UpdateRegistry -
  40. // Adds or removes system registry entries for CAlarmPropPage
  41.  
  42. BOOL CAlarmPropPage::CAlarmPropPageFactory::UpdateRegistry(BOOL bRegister)
  43. {
  44.     // TODO: Define string resource for page type; replace '0' below with ID.
  45.  
  46.     if (bRegister)
  47.         return AfxOleRegisterPropertyPageClass(AfxGetInstanceHandle(),
  48.             m_clsid, IDS_ALARM_PPG);
  49.     else
  50.         return AfxOleUnregisterClass(m_clsid, NULL);
  51. }
  52.  
  53.  
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CAlarmPropPage::CAlarmPropPage - Constructor
  56.  
  57. // TODO: Define string resource for page caption; replace '0' below with ID.
  58.  
  59. CAlarmPropPage::CAlarmPropPage() :
  60.     COlePropertyPage(IDD, IDS_ALARM_PPG_CAPTION)
  61. {
  62.     //{{AFX_DATA_INIT(CAlarmPropPage)
  63.     m_AlarmHour = 0;
  64.     m_AlarmMinute = 0;
  65.     m_AlarmSound = _T("");
  66.     m_AlarmCommand = _T("");
  67.     m_bAlarmSet = FALSE;
  68.     m_AlarmType = -1;
  69.     //}}AFX_DATA_INIT
  70. }
  71.  
  72.  
  73. /////////////////////////////////////////////////////////////////////////////
  74. // CAlarmPropPage::DoDataExchange - Moves data between page and properties
  75.  
  76. void CAlarmPropPage::DoDataExchange(CDataExchange* pDX)
  77. {
  78.     // NOTE: ClassWizard will add DDP, DDX, and DDV calls here
  79.     //    DO NOT EDIT what you see in these blocks of generated code !
  80.     //{{AFX_DATA_MAP(CAlarmPropPage)
  81.     DDP_Text(pDX, IDC_ALARM_HOUR, m_AlarmHour, _T("AlarmHour") );
  82.     DDX_Text(pDX, IDC_ALARM_HOUR, m_AlarmHour);
  83.     DDV_MinMaxInt(pDX, m_AlarmHour, 0, 23);
  84.     DDP_Text(pDX, IDC_ALARM_MINUTE, m_AlarmMinute, _T("AlarmMinute") );
  85.     DDX_Text(pDX, IDC_ALARM_MINUTE, m_AlarmMinute);
  86.     DDV_MinMaxInt(pDX, m_AlarmMinute, 0, 59);
  87.     DDP_Text(pDX, IDC_ALARM_SOUND, m_AlarmSound, _T("AlarmSound") );
  88.     DDX_Text(pDX, IDC_ALARM_SOUND, m_AlarmSound);
  89.     DDP_Text(pDX, IDC_ALARM_COMMAND, m_AlarmCommand, _T("AlarmCommand") );
  90.     DDX_Text(pDX, IDC_ALARM_COMMAND, m_AlarmCommand);
  91.     DDP_Check(pDX, IDC_ALARM_SET, m_bAlarmSet, _T("AlarmSet") );
  92.     DDX_Check(pDX, IDC_ALARM_SET, m_bAlarmSet);
  93.     DDP_CBIndex(pDX, IDC_ALARM_TYPE, m_AlarmType, _T("AlarmType") );
  94.     DDX_CBIndex(pDX, IDC_ALARM_TYPE, m_AlarmType);
  95.     //}}AFX_DATA_MAP
  96.     DDP_PostProcessing(pDX);
  97. }
  98.  
  99.  
  100. /////////////////////////////////////////////////////////////////////////////
  101. // CAlarmPropPage message handlers
  102. //
  103. // This routine allows the user to the alarm's sound file using
  104. // the Window's Open File common dialog.
  105. void CAlarmPropPage::OnSoundFileSelect() 
  106. {
  107.     CString strFilter("Sound Files(*.wav, *.mid) | *.wav;*.mid | "
  108.         "All Files(*.*) | *.* ||");
  109.     CFileDialog dlg(TRUE, 
  110.                     NULL, 
  111.                     m_AlarmSound,
  112.                     OFN_FILEMUSTEXIST | OFN_HIDEREADONLY,
  113.                     strFilter,
  114.                     this);
  115.  
  116.     if(IDOK == dlg.DoModal())
  117.     {
  118.         // Update the sound member variable
  119.         m_AlarmSound = dlg.GetPathName();
  120.         // Update the sound control string
  121.         CEdit* pAlarmSound = (CEdit*)GetDlgItem(IDC_ALARM_SOUND);
  122.         pAlarmSound->SetWindowText(m_AlarmSound);
  123.     }
  124. }
  125.   
  126.  
  127. BOOL CAlarmPropPage::OnInitDialog() 
  128. {
  129.     COlePropertyPage::OnInitDialog();
  130.     
  131.     // Load the combobox with the alarm type selections and set
  132.     // the appropriate selection
  133.     CComboBox* pcb = (CComboBox*)GetDlgItem(IDC_ALARM_TYPE);
  134.     ASSERT(pcb != NULL);
  135.  
  136.     for (int i = IDS_ALARMTYPE_EVENT; i <= IDS_ALARMTYPE_ALL ; i++)
  137.     {
  138.         CString str;
  139.         str.LoadString(i);
  140.         pcb->AddString(LPCTSTR(str));
  141.     }
  142.     pcb->SetCurSel(m_AlarmType == -1 ? 0 : m_AlarmType);
  143.     
  144.     return TRUE;  // return TRUE unless you set the focus to a control
  145.                   // EXCEPTION: OCX Property Pages should return FALSE
  146. }
  147.