Datecal.cpp
资源名称:TestClnd.zip [点击查看]
上传用户:shlb123
上传日期:2007-01-01
资源大小:73k
文件大小:6k
源码类别:
ActiveX/DCOM/ATL
开发平台:
Visual C++
- // DateCal.cpp : implementation file
- //written by : Alexei Valyayev 07/05/98
- #include "stdafx.h"
- #include "TestClnd.h"
- #include "datecal.h"
- #include "font.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- char* CDateCal::MONTHS[12] = { "January", "February", "March", "April",
- "May", "June", "July", "August",
- "September", "October", "November", "December" };
- /////////////////////////////////////////////////////////////////////////////
- // CDateCal dialog
- CDateCal::CDateCal(CWnd* pParent /*=NULL*/)
- : CDialog(CDateCal::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CDateCal)
- //}}AFX_DATA_INIT
- }
- void CDateCal::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDateCal)
- DDX_Control(pDX, IDC_RESET, m_butReset);
- DDX_Control(pDX, IDC_PREV_YEAR, m_butPrevYear);
- DDX_Control(pDX, IDC_PREV_MONTH, m_butPrevMonth);
- DDX_Control(pDX, IDC_NEXT_YEAR, m_butNextYear);
- DDX_Control(pDX, IDC_NEXT_MONTH, m_butNextMonth);
- DDX_Control(pDX, IDC_DATE_CALENDAR, m_calDate);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CDateCal, CDialog)
- //{{AFX_MSG_MAP(CDateCal)
- ON_BN_CLICKED(IDC_PREV_YEAR, OnPrevYear)
- ON_BN_CLICKED(IDC_PREV_MONTH, OnPrevMonth)
- ON_BN_CLICKED(IDC_RESET, OnReset)
- ON_BN_CLICKED(IDC_NEXT_MONTH, OnNextMonth)
- ON_BN_CLICKED(IDC_NEXT_YEAR, OnNextYear)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDateCal message handlers
- BOOL CDateCal::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // TODO: Add extra initialization here
- m_calDate.SetYear(m_nYear);
- m_calDate.SetMonth(m_nMonth);
- m_calDate.SetDay(m_nDay);
- m_hIcon = AfxGetApp()->LoadIcon(IDI_TODAY);
- if (NULL != m_hIcon){
- m_butReset.ModifyStyle(0, BS_ICON);
- m_butReset.SetIcon(m_hIcon);
- }
- else
- m_hIcon = NULL;
- m_hIcon = AfxGetApp()->LoadIcon(IDI_PREVYEAR);
- if (NULL != m_hIcon){
- m_butPrevYear.ModifyStyle(0, BS_ICON);
- m_butPrevYear.SetIcon(m_hIcon);
- }
- else
- m_hIcon = NULL;
- m_hIcon = AfxGetApp()->LoadIcon(IDI_PREVMONTH);
- if (NULL != m_hIcon){
- m_butPrevMonth.ModifyStyle(0, BS_ICON);
- m_butPrevMonth.SetIcon(m_hIcon);
- }
- else
- m_hIcon = NULL;
- m_hIcon = AfxGetApp()->LoadIcon(IDI_NEXTMONTH);
- if (NULL != m_hIcon){
- m_butNextMonth.ModifyStyle(0, BS_ICON);
- m_butNextMonth.SetIcon(m_hIcon);
- }
- else
- m_hIcon = NULL;
- m_hIcon = AfxGetApp()->LoadIcon(IDI_NEXTYEAR);
- if (NULL != m_hIcon){
- m_butNextYear.ModifyStyle(0, BS_ICON);
- m_butNextYear.SetIcon(m_hIcon);
- }
- else
- m_hIcon = NULL;
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CDateCal::OnOK()
- {
- // TODO: Add extra validation here
- m_nDay = m_calDate.GetDay();
- m_nMonth = m_calDate.GetMonth();
- m_nYear = m_calDate.GetYear();
- CDialog::OnOK();
- }
- void CDateCal::OnPrevYear()
- {
- // TODO: Add your control notification handler code here
- m_calDate.PreviousYear();
- }
- void CDateCal::OnPrevMonth()
- {
- // TODO: Add your control notification handler code here
- m_calDate.PreviousMonth();
- }
- void CDateCal::OnReset()
- {
- // TODO: Add your control notification handler code here
- m_calDate.Today();
- }
- void CDateCal::OnNextMonth()
- {
- // TODO: Add your control notification handler code here
- m_calDate.NextMonth();
- }
- void CDateCal::OnNextYear()
- {
- // TODO: Add your control notification handler code here
- m_calDate.NextYear();
- }
- BEGIN_EVENTSINK_MAP(CDateCal, CDialog)
- //{{AFX_EVENTSINK_MAP(CDateCal)
- ON_EVENT(CDateCal, IDC_DATE_CALENDAR, 4 /* NewYear */, OnNewYearDateCalendar, VTS_NONE)
- ON_EVENT(CDateCal, IDC_DATE_CALENDAR, 3 /* NewMonth */, OnNewMonthDateCalendar, VTS_NONE)
- ON_EVENT(CDateCal, IDC_DATE_CALENDAR, 2 /* BeforeUpdate */, OnBeforeUpdateDateCalendar, VTS_PI2)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
- void CDateCal::OnBeforeUpdateDateCalendar(short FAR* Cancel)
- {
- // TODO: Add your control notification handler code here
- m_nDay = m_calDate.GetDay();
- m_nMonth = m_calDate.GetMonth();
- m_nYear = m_calDate.GetYear();
- Cancel;//not used
- }
- ///////////////////////////////////////////////
- // change month by combobox
- void CDateCal::OnNewMonthDateCalendar()
- {
- // TODO: Add your control notification handler code here
- int nID;
- CWnd* pWnd = GetFocus();
- nID = pWnd->GetDlgCtrlID();
- CString string;
- pWnd->GetWindowText( string );
- if(1==nID){//nID =1 - Month ID combobox
- int nDif = GetNewMonth(string);
- if(nDif) {//if change month
- nDif-=m_nMonth;
- if(nDif>0){//change month in a calendar
- while(nDif--)
- OnNextMonth();
- }
- else if (nDif<0){
- while(nDif++)
- OnPrevMonth();
- }
- }
- }
- }
- /////////////////////////////////////////////////////////
- //
- void CDateCal::OnNewYearDateCalendar()
- {
- // TODO: Add your control notification handler code here
- int nID;
- CWnd* pWnd = GetFocus();
- nID = pWnd->GetDlgCtrlID();
- CString string;
- pWnd->GetWindowText( string );
- if(2==nID){//nID =2 - ID combobox Year
- int nDif = atoi(string) - m_nYear;
- if(nDif>0){//if increase Year
- while(nDif--)
- OnNextYear();//change year
- }
- else if (nDif<0){//if decrease Year
- while(nDif++)
- OnPrevYear();//change Year in a calendar
- }
- }
- }
- ////////////////////////////////////////////////////////
- // difference between values of a month in calendar
- //and a month in a combobox
- int CDateCal::GetNewMonth(const CString& string ) const
- {
- char** strptr;
- strptr = MONTHS;
- for(int j = 0; j< 12;j++)
- if(!string.Compare(*(strptr++)))
- return j+1;
- return 0;//error or not changed month
- }