home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / ole / wordpad / datedial.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  3KB  |  120 lines

  1. // datedial.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "wordpad.h"
  15. #include "datedial.h"
  16. #include "helpids.h"
  17. #include <winnls.h>
  18.  
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char BASED_CODE THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. SYSTEMTIME CDateDialog::m_time;
  25. LCID CDateDialog::m_id;
  26. CListBox* CDateDialog::m_pListBox = NULL;
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CDateDialog dialog
  30.  
  31. const DWORD CDateDialog::m_nHelpIDs[] =
  32. {
  33.     IDC_DATEDIALOG_LIST, IDH_WORDPAD_TIMEDATE,
  34.     IDC_STATIC_HEADING, IDH_WORDPAD_TIMEDATE,
  35.     IDOK, IDH_WORDPAD_TIMEDATE,
  36.     IDCANCEL, IDH_WORDPAD_TIMEDATE,
  37.     0 , 0
  38. };
  39.  
  40. CDateDialog::CDateDialog(CWnd* pParent /*=NULL*/)
  41.     : CCSDialog(CDateDialog::IDD, pParent)
  42. {
  43.     //{{AFX_DATA_INIT(CDateDialog)
  44.     m_strSel = _T("");
  45.     //}}AFX_DATA_INIT
  46. }
  47.  
  48.  
  49. void CDateDialog::DoDataExchange(CDataExchange* pDX)
  50. {
  51.     CCSDialog::DoDataExchange(pDX);
  52.     //{{AFX_DATA_MAP(CDateDialog)
  53.     DDX_Control(pDX, IDC_DATEDIALOG_LIST, m_listBox);
  54.     DDX_LBString(pDX, IDC_DATEDIALOG_LIST, m_strSel);
  55.     //}}AFX_DATA_MAP
  56. }
  57.  
  58.  
  59. BEGIN_MESSAGE_MAP(CDateDialog, CCSDialog)
  60.     //{{AFX_MSG_MAP(CDateDialog)
  61.     ON_LBN_DBLCLK(IDC_DATEDIALOG_LIST, OnDblclkDatedialogList)
  62.     //}}AFX_MSG_MAP
  63. END_MESSAGE_MAP()
  64.  
  65.  
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CDateDialog message handlers
  68.  
  69. BOOL CDateDialog::OnInitDialog()
  70. {
  71.     CCSDialog::OnInitDialog();
  72.  
  73.     m_pListBox = &m_listBox; // set static member
  74.     GetLocalTime(&m_time);
  75.     m_id = GetUserDefaultLCID();
  76.  
  77.     EnumDateFormats(DateFmtEnumProc, m_id, DATE_SHORTDATE);
  78.     EnumDateFormats(DateFmtEnumProc, m_id, DATE_LONGDATE);
  79.     EnumTimeFormats(TimeFmtEnumProc, m_id, 0);
  80.  
  81.     m_pListBox = NULL;
  82.     m_listBox.SetCurSel(0);
  83.  
  84.     return TRUE;  // return TRUE unless you set the focus to a control
  85.                   // EXCEPTION: OCX Property Pages should return FALSE
  86. }
  87.  
  88. BOOL CALLBACK CDateDialog::DateFmtEnumProc(LPTSTR lpszFormatString)
  89. {
  90.     ASSERT(m_pListBox != NULL);
  91.     TCHAR buf[256];
  92.     VERIFY(GetDateFormat(m_id, 0, &m_time, lpszFormatString, buf, 256));
  93.     // we can end up with same format because a format with leading
  94.     // zeroes may be the same as one without when a number is big enough
  95.     // e.g. 09/10/94 9/10/94 are different but 10/10/94 and 10/10/94 are
  96.     // the same
  97.     if (m_pListBox->FindStringExact(-1,buf) == CB_ERR)
  98.         m_pListBox->AddString(buf);
  99.     return TRUE;
  100. }
  101.  
  102. BOOL CALLBACK CDateDialog::TimeFmtEnumProc(LPTSTR lpszFormatString)
  103. {
  104.     ASSERT(m_pListBox != NULL);
  105.     TCHAR buf[256];
  106.     VERIFY(GetTimeFormat(m_id, 0, &m_time, lpszFormatString, buf, 256));
  107.     // we can end up with same format because a format with leading
  108.     // zeroes may be the same as one without when a number is big enough
  109.     // e.g. 09/10/94 9/10/94 are different but 10/10/94 and 10/10/94 are
  110.     // the same
  111.     if (m_pListBox->FindStringExact(-1,buf) == CB_ERR)
  112.         m_pListBox->AddString(buf);
  113.     return TRUE;
  114. }
  115.  
  116. void CDateDialog::OnDblclkDatedialogList()
  117. {
  118.     OnOK();
  119. }
  120.