home *** CD-ROM | disk | FTP | other *** search
/ Troubleshooting Netware Systems / CSTRIAL0196.BIN / attach / msj / v10n04 / multilin.exe / TIMEFORM.CPP < prev    next >
C/C++ Source or Header  |  1995-04-01  |  5KB  |  169 lines

  1. // timeform.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "global.h"
  6. #include "timeform.h"
  7.  
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char BASED_CODE THIS_FILE[] = __FILE__;
  11. #endif
  12.  
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CTimeFormat dialog
  15.  
  16.  
  17. CTimeFormat::CTimeFormat(CWnd* pParent /*=NULL*/)
  18.     : CDialog(CTimeFormat::IDD, pParent)
  19. {
  20.     //{{AFX_DATA_INIT(CTimeFormat)
  21.         // NOTE: the ClassWizard will add member initialization here
  22.     //}}AFX_DATA_INIT
  23. }
  24.  
  25.  
  26. void CTimeFormat::DoDataExchange(CDataExchange* pDX)
  27. {
  28.     CDialog::DoDataExchange(pDX);
  29.     //{{AFX_DATA_MAP(CTimeFormat)
  30.         // NOTE: the ClassWizard will add DDX and DDV calls here
  31.     //}}AFX_DATA_MAP
  32. }
  33.  
  34.  
  35. BEGIN_MESSAGE_MAP(CTimeFormat, CDialog)
  36.     //{{AFX_MSG_MAP(CTimeFormat)
  37.     ON_LBN_DBLCLK(IDC_TIMEFORMATS, OnDblclkTimeformats)
  38.     ON_EN_CHANGE(IDC_CUSTOM, OnChangeCustom)
  39.     //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41.  
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CTimeFormat message handlers
  45.  
  46. BOOL CTimeFormat::OnInitDialog() 
  47. {
  48.     CDialog::OnInitDialog();
  49.     
  50.     // TODO: Add extra initialization here
  51.     AppendTimeFormat( LOCALE_STIMEFORMAT | LOCALE_NOUSEROVERRIDE);         
  52.     AppendTimeFormat( LOCALE_STIMEFORMAT);      
  53.   
  54.        
  55.  
  56.     SendDlgItemMessage( IDC_TIMEFORMATS, LB_SETCURSEL, 0, 0);
  57.     SendMessage( WM_COMMAND, IDC_TIMEFORMATS, 0);
  58.  
  59.     // Format a sample date
  60.     OnDblclkTimeformats();    
  61.  
  62.     return TRUE;  // return TRUE unless you set the focus to a control
  63.                   // EXCEPTION: OCX Property Pages should return FALSE
  64. }
  65.         
  66. #define STRINGLEN 128
  67.  
  68. /////////////////////////////////////////////////////
  69. // EnumTimeFormatsProc
  70. //
  71. // Add the given date format string to the list box and
  72. // set that item's data to TIME_SHORTFORM or TIME_LONGFORM
  73.  
  74. #define MAXSAMPLELEN 128
  75. #define MAXTIMEFORMAT 50
  76.  
  77. ////////////////////////////////
  78. // ShowSampleTime
  79. //
  80.  
  81. void CTimeFormat::ShowSampleTime( CString& szTimeFormat, DWORD dwTimeFlags)
  82. {
  83.     static TCHAR szSampleTime[ MAXSAMPLELEN];
  84.  
  85.     GetTimeFormat( GetThreadLocale(),        // use this thread's locale
  86.                    dwTimeFlags,              // flags passed into this function
  87.                    NULL,                     // use current system time
  88.                    szTimeFormat,             // format seleted by user
  89.                    szSampleTime,             // for formatted date
  90.                    MAXSAMPLELEN);            // date buffer length
  91.  
  92.     SetDlgItemText( IDC_FORMATTED, szSampleTime);
  93. }
  94.  
  95. BOOL  CTimeFormat::AppendTimeFormat(
  96.         DWORD dwFlags)     // pointer to date format string
  97. {
  98.     static TCHAR szFmt[STRINGLEN] = TEXT("");
  99.     static TCHAR szTmp[STRINGLEN] = TEXT("");
  100.     LONG lTmp;
  101.     LONG lIndex = SendDlgItemMessage( IDC_TIMEFORMATS,
  102.                                       LB_GETCOUNT,
  103.                                       0, 0);
  104.     int nBufLen = GetLocaleInfo( GetThreadLocale(), dwFlags, szFmt, STRINGLEN);
  105.  
  106.     if ( nBufLen == 0 )
  107.     {
  108.         LONG lRC = GetLastError();
  109.     }
  110.  
  111.                                 // Is this format string already in the list?
  112.     for ( lTmp = 0; lTmp < lIndex; ++lTmp )
  113.     {
  114.         SendDlgItemMessage( IDC_TIMEFORMATS,
  115.                             LB_GETTEXT,
  116.                             lTmp,
  117.                             (LPARAM)szTmp);
  118.  
  119.         if ( lstrcmp( szFmt, szTmp) == 0 )
  120.             return( TRUE);      // Already in list
  121.     }
  122.     lIndex = SendDlgItemMessage( IDC_TIMEFORMATS,
  123.                                  LB_ADDSTRING, 
  124.                                  0, 
  125.                                  (LPARAM)szFmt);
  126.  
  127.     if ( ! (lIndex = LB_ERR || lIndex == LB_ERRSPACE) )
  128.     {
  129.         return( SendDlgItemMessage( IDC_TIMEFORMATS,
  130.                                     LB_SETITEMDATA, 
  131.                                     lIndex, 
  132.                                     (LPARAM)dwFlags) == LB_ERR ? FALSE : TRUE);
  133.     }
  134.     return( FALSE);
  135. }
  136.  
  137. void CTimeFormat::OnChangeCustom() 
  138. {
  139.     // TODO: Add your control notification handler code here
  140.     CString szTimeFormat;
  141.     SendDlgItemMessage( IDC_CUSTOM, 
  142.                         WM_GETTEXT,
  143.                         MAXTIMEFORMAT, 
  144.                         (LPARAM)(szTimeFormat.GetBufferSetLength(MAXTIMEFORMAT)));
  145.     DWORD dwTimeFlags = 0;
  146.  
  147.     ShowSampleTime( szTimeFormat, dwTimeFlags);
  148. }
  149.  
  150. void CTimeFormat::OnDblclkTimeformats() 
  151. {
  152.     // TODO: Add your control notification handler code here
  153.     
  154.     LONG lIndex = SendDlgItemMessage( IDC_TIMEFORMATS, 
  155.                                       LB_GETCURSEL, 0, 0);
  156.  
  157.     CString szTimeFormat;
  158.     SendDlgItemMessage( IDC_TIMEFORMATS, 
  159.                         LB_GETTEXT,
  160.                         (WPARAM)lIndex, 
  161.                         (LPARAM)(szTimeFormat.GetBufferSetLength(MAXTIMEFORMAT)));
  162.     DWORD dwTimeFlags = SendDlgItemMessage( IDC_TIMEFORMATS, 
  163.                                                   LB_GETITEMDATA, 
  164.                                                   (WPARAM)lIndex, 0);
  165.     ShowSampleTime( szTimeFormat, dwTimeFlags);
  166. }
  167.  
  168.  
  169.