面向对象程序设计课程设计报告《电子时钟》(C++) 下载本文

}

KillTimer(1);//清除计时器

void CDateTimeView::OnTimer(UINT nIDEvent) { }

void CDateTimeView::OnSetting() //设置时间函数 { }

void CDateTimeView::OnReset() //重获系统时间函数 { }

BOOL CDateTimeView::OnEraseBkgnd(CDC* pDC) { }

int CDateTimeView::Week(int y,int m,int d) //星期计算函数 {

Invalidate(false); //计时完成,调用Invalidate()函数重绘试图 CView::OnTimer(nIDEvent);

CDateTimeDoc* pDoc = GetDocument(); CSetting cst;

cst.year=&pDoc->year; //把文档类的相应属性赋给编辑框 cst.month=&pDoc->month; cst.day=&pDoc->day; cst.hour=&pDoc->hour; cst.minute=&pDoc->minute; cst.second=&pDoc->second; cst.DoModal();

GetDateTime(); Invalidate();

return TRUE;

int g, f=y-1901+(y-1901)/4+2;

20

}

switch(m) {

case 1:g=f+d;break; case 2:g=f+d+31;break; case 3:g=f+d+59;break; case 4:g=f+d+90;break; case 5:g=f+d+120;break; case 6:g=f+d+151;break; case 7:g=f+d+181;break; case 8:g=f+d+212;break; case 9:g=f+d+243;break; case 10:g=f+d+273;break; case 11:g=f+d+304;break; case 12:g=f+d+334;break; }

if(y%4==0&&y0!=0&&m>2) return (g-1)%7;

g++;

#if !defined(AFX_SETTING_H__D569349B_C1DA_4639_BC4F_1B59A0E7C554__INCLUDED_)

#define

AFX_SETTING_H__D569349B_C1DA_4639_BC4F_1B59A0E7C554__INCLUDED_

#if _MSC_VER > 1000 #pragma once

#endif // _MSC_VER > 1000

// Setting.h文件,对话框类,负责设置时间 #include \#include \class CSetting : public CDialog {

21

public: CSetting(CWnd* pParent = NULL); // standard constructor enum { IDD = IDD_SETTING }; CSpinButtonCtrl m_syear; CSpinButtonCtrl m_ssecond; CSpinButtonCtrl m_smonth; CSpinButtonCtrl m_sminute; CSpinButtonCtrl m_shour; CSpinButtonCtrl m_sday; int m_year; int m_day; int m_hour; int m_minute; int m_month; int

m_second;

int *year,*month,*day,*hour,*minute,*second; protected:

virtual void DoDataExchange(CDataExchange* pDX); afx_msg void OnChangeEditYear(){}; afx_msg void OnChangeEditMonth(){}; afx_msg void OnChangeEditDay(){}; afx_msg void OnChangeEditHour(){}; afx_msg void OnChangeEditMinute(){}; afx_msg void OnChangeEditSecond(){}; virtual BOOL OnInitDialog(); virtual void OnOK();

afx_msg void OnOutofmemorySpinYear(NMHDR* pResult);

DECLARE_MESSAGE_MAP()

}; #endif

22

// DDX/DDV support pNMHDR, LRESULT*

// Setting.cpp文件 #include \#include \#include \#ifdef _DEBUG

#define new DEBUG_NEW #undef THIS_FILE

static char THIS_FILE[] = __FILE__; #endif

CSetting::CSetting(CWnd* pParent /*=NULL*/) { }

void CSetting::DoDataExchange(CDataExchange* pDX) {

: CDialog(CSetting::IDD, pParent)

m_year = 0; m_day = 0; m_hour = 0; m_minute = 0; m_month = 0; m_second = 0;

CDialog::DoDataExchange(pDX);

DDX_Control(pDX, IDC_SPIN_YEAR, m_syear); DDX_Control(pDX, IDC_SPIN_SECOND, m_ssecond); DDX_Control(pDX, IDC_SPIN_MONTH, m_smonth); DDX_Control(pDX, IDC_SPIN_MINUTE, m_sminute); DDX_Control(pDX, IDC_SPIN_HOUR, m_shour); DDX_Control(pDX, IDC_SPIN_DAY, m_sday); DDX_Text(pDX, IDC_EDIT_YEAR, m_year); DDV_MinMaxInt(pDX, m_year, 1900, 2999); DDX_Text(pDX, IDC_EDIT_DAY, m_day);

23