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

}

#ifdef _DEBUG

void CDateTimeDoc::AssertValid() const { }

void CDateTimeDoc::Dump(CDumpContext& dc) const { }

#endif //_DEBUG

// DateTimeView.h文件,负责绘图显示和时钟定义主要功能的函数

#if !defined(AFX_DATETIMEVIEW_H__D7609974_EA26_4AB5_82B0_A04A15A1C9F2__INCLUDED_)

#define

AFX_DATETIMEVIEW_H__D7609974_EA26_4AB5_82B0_A04A15A1C9F2__INCLUDED_

#if _MSC_VER > 1000 #pragma once

#endif // _MSC_VER > 1000 #include \#include \

class CDateTimeView : public CView { protected:

CDateTimeView();

DECLARE_DYNCREATE(CDateTimeView) CDocument::Dump(dc); CDocument::AssertValid();

public:

CDateTimeDoc* GetDocument();

private:

12

int flag; int _sec1; int _sec2; public:

virtual void OnDraw(CDC* pDC); // overridden to draw this view virtual BOOL PreCreateWindow(CREATESTRUCT& cs); virtual void OnInitialUpdate();

public:

int Week(int,int,int); //计算星期函数 void RunTime(); //运行时间函数 void Change(); //int型转CString函数 void GetDateTime(); //获取系统时间函数 virtual ~CDateTimeView();

#ifdef _DEBUG

virtual void AssertValid() const;

virtual void Dump(CDumpContext& dc) const;

#endif protected: protected: };

#ifndef _DEBUG

inline CDateTimeDoc* CDateTimeView::GetDocument() { return (CDateTimeDoc*)m_pDocument; } #endif

// DateTimeView.cpp 文件

13

afx_msg void OnDestroy();

afx_msg void OnTimer(UINT nIDEvent); afx_msg void OnSetting(); afx_msg void OnReset();

afx_msg BOOL OnEraseBkgnd(CDC* pDC); DECLARE_MESSAGE_MAP()

#include \#include \#include \#include \#ifdef _DEBUG

#define new DEBUG_NEW #undef THIS_FILE

static char THIS_FILE[] = __FILE__; #endif

IMPLEMENT_DYNCREATE(CDateTimeView, CView) BEGIN_MESSAGE_MAP(CDateTimeView, CView)

ON_WM_DESTROY() ON_WM_TIMER()

ON_COMMAND(IDD_SETTING, OnSetting) ON_COMMAND(ID_RESET, OnReset) ON_WM_ERASEBKGND() END_MESSAGE_MAP()

CDateTimeView::CDateTimeView() { }

CDateTimeView::~CDateTimeView() { }

BOOL CDateTimeView::PreCreateWindow(CREATESTRUCT& cs) { }

void CDateTimeView::OnDraw(CDC* pDC) {

flag=0;_sec1=_sec2=0;

return CView::PreCreateWindow(cs);

CDateTimeDoc* pDoc = GetDocument();

14

ASSERT_VALID(pDoc); CClientDC dc(this); // 获得窗体大小 CRect rect;

GetWindowRect(&rect);

int nWidth = rect.Width(); int nHeight= rect.Height();

//在内存中创建一个与屏幕绘图区域一致的对象

CDC MemDC; CBitmap MemBitmap;

MemDC.CreateCompatibleDC(NULL);

MemBitmap.CreateCompatibleBitmap(&dc, nWidth, nHeight); CBitmap *pOldBit = MemDC.SelectObject(&MemBitmap);

time_t curtime=time(0); tm getsec=*localtime(&curtime); if(flag==0) { }

curtime=time(0);

getsec=*localtime(&curtime); _sec2=getsec.tm_sec;

if(_sec2!=_sec1) //和系统时间比较判断是不是需要加1秒 { }

MemDC.SetTextColor(RGB(0,0,255)); //文本颜色 int cHeight; UINT position=0;

15

GetDateTime();

_sec1=_sec2=getsec.tm_sec;

_sec1=_sec2; RunTime();