From: boca4711 <boc...@us...> - 2005-10-16 12:06:04
|
Update of /cvsroot/anyedit/AnyEditv2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18549 Added Files: DateDlg.cpp DateDlg.h Log Message: Date dialog to insert date in several formats. --- NEW FILE: DateDlg.h --- // datedial.h : header file // // This is a part of the Microsoft Foundation Classes C++ library. // Copyright (c) Microsoft Corporation. All rights reserved. // // This source code is only intended as a supplement to the // Microsoft Foundation Classes Reference and related // electronic documentation provided with the library. // See these sources for detailed information regarding the // Microsoft Foundation Classes product. ///////////////////////////////////////////////////////////////////////////// // CDateDialog dialog class CDateDialog : public CDialog { // Construction public: static CStringArray* m_pArDateFormats; CDateDialog(CWnd* pParent = NULL); // standard constructor // Attributes static SYSTEMTIME m_time; static LCID m_id; static CListBox* m_pListBox; static BOOL CALLBACK DateFmtEnumProc(LPTSTR lpszFormatString); static BOOL CALLBACK TimeFmtEnumProc(LPTSTR lpszFormatString); // Dialog Data //{{AFX_DATA(CDateDialog) enum { IDD = IDD_DATEDIALOG }; CListBox m_listBox; CString m_strSel; //}}AFX_DATA // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CDateDialog) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: CStringArray m_arDateFormats; // static const DWORD m_nHelpIDs[]; // virtual const DWORD* GetHelpIDs() {return m_nHelpIDs;} // Generated message map functions //{{AFX_MSG(CDateDialog) virtual BOOL OnInitDialog(); afx_msg void OnDblclkDatedialogList(); afx_msg void OnButtonDateDefault(); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; --- NEW FILE: DateDlg.cpp --- // datedial.cpp : implementation file // // This is a part of the Microsoft Foundation Classes C++ library. // Copyright (c) Microsoft Corporation. All rights reserved. // // This source code is only intended as a supplement to the // Microsoft Foundation Classes Reference and related // electronic documentation provided with the library. // See these sources for detailed information regarding the // Microsoft Foundation Classes product. #include "stdafx.h" #include "AnyEdit.h" #include "DateDlg.h" #include <winnls.h> #ifdef _DEBUG #undef THIS_FILE static char BASED_CODE THIS_FILE[] = __FILE__; #endif SYSTEMTIME CDateDialog::m_time; LCID CDateDialog::m_id; CListBox* CDateDialog::m_pListBox = NULL; CStringArray* CDateDialog::m_pArDateFormats = NULL; ///////////////////////////////////////////////////////////////////////////// // CDateDialog dialog /* const DWORD CDateDialog::m_nHelpIDs[] = { IDC_DATEDIALOG_LIST, IDH_WORDPAD_TIMEDATE, IDC_STATIC_HEADING, IDH_WORDPAD_TIMEDATE, IDOK, IDH_WORDPAD_TIMEDATE, IDCANCEL, IDH_WORDPAD_TIMEDATE, 0 , 0 }; */ CDateDialog::CDateDialog(CWnd* pParent /*=NULL*/) : CDialog(CDateDialog::IDD, pParent) { //{{AFX_DATA_INIT(CDateDialog) m_strSel = _T(""); //}}AFX_DATA_INIT } void CDateDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDateDialog) DDX_Control(pDX, IDC_DATEDIALOG_LIST, m_listBox); DDX_LBString(pDX, IDC_DATEDIALOG_LIST, m_strSel); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CDateDialog, CDialog) //{{AFX_MSG_MAP(CDateDialog) ON_LBN_DBLCLK(IDC_DATEDIALOG_LIST, OnDblclkDatedialogList) ON_BN_CLICKED(IDC_BUTTON_DATE_DEFAULT, OnButtonDateDefault) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDateDialog message handlers BOOL CDateDialog::OnInitDialog() { CDialog::OnInitDialog(); m_pListBox = &m_listBox; // set static member m_pArDateFormats = &m_arDateFormats; m_arDateFormats.RemoveAll(); GetLocalTime(&m_time); m_id = GetUserDefaultLCID(); EnumDateFormats(DateFmtEnumProc, m_id, DATE_SHORTDATE); EnumDateFormats(DateFmtEnumProc, m_id, DATE_LONGDATE); EnumTimeFormats(TimeFmtEnumProc, m_id, 0); m_pListBox = NULL; m_pArDateFormats = NULL; m_listBox.SetCurSel(0); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } BOOL CALLBACK CDateDialog::DateFmtEnumProc(LPTSTR lpszFormatString) { ASSERT(m_pListBox != NULL); TCHAR buf[256]; VERIFY(GetDateFormat(m_id, 0, &m_time, lpszFormatString, buf, 256)); // we can end up with same format because a format with leading // zeroes may be the same as one without when a number is big enough // e.g. 09/10/94 9/10/94 are different but 10/10/94 and 10/10/94 are // the same if (m_pListBox->FindStringExact(-1,buf) == CB_ERR) { int nPos = m_pListBox->AddString(buf); int nIndex = m_pArDateFormats->Add(lpszFormatString); m_pListBox->SetItemData(nPos, nIndex); } return TRUE; } BOOL CALLBACK CDateDialog::TimeFmtEnumProc(LPTSTR lpszFormatString) { ASSERT(m_pListBox != NULL); TCHAR buf[256]; VERIFY(GetTimeFormat(m_id, 0, &m_time, lpszFormatString, buf, 256)); // we can end up with same format because a format with leading // zeroes may be the same as one without when a number is big enough // e.g. 09/10/94 9/10/94 are different but 10/10/94 and 10/10/94 are // the same if (m_pListBox->FindStringExact(-1,buf) == CB_ERR) { int nPos = m_pListBox->AddString(buf); int nIndex = m_pArDateFormats->Add(lpszFormatString); m_pListBox->SetItemData(nPos, nIndex); } return TRUE; } void CDateDialog::OnDblclkDatedialogList() { OnOK(); } void CDateDialog::OnButtonDateDefault() { CConfigFile* pConfigFile = theApp.GetConfigFile(); int nIndex = m_listBox.GetItemData(m_listBox.GetCurSel()); pConfigFile->SetDefaultDateFormat(m_arDateFormats[nIndex]); } |