CFont font; cHeight=16+3*8;
font.CreateFont(-cHeight,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,ANSI_C
HARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_MODERN,\ //字体格式
CFont *oldFont=MemDC.SelectObject (&font); position+=cHeight; flag=1; Change();
pDoc->str1=pDoc->str_year+\年\月\日\pDoc->str2=pDoc->str_hour+\CBrush MyBrush;
CBrush *pOldBrush=pDC->SelectObject(&MyBrush); GetClientRect(&rect);
MemDC.Rectangle(-1,-1,400,260); MemDC.SelectObject(pOldBrush); MemDC.TextOut(25,25,pDoc->str1); MemDC.TextOut(140,70,pDoc->str3); MemDC.TextOut(95,122,pDoc->str2); //将内存中绘制的图像复制到当前设备
dc.BitBlt(0, 0, nWidth, nHeight, &MemDC, 0, 0, SRCCOPY);
//销毁对象
MemBitmap.DeleteObject(); MemDC.DeleteDC(); }
#ifdef _DEBUG
void CDateTimeView::AssertValid() const { }
void CDateTimeView::Dump(CDumpContext& dc) const {
16
CView::AssertValid();
}
CView::Dump(dc);
CDateTimeDoc* CDateTimeView::GetDocument() // non-debug version is inline { }
#endif //_DEBUG
void CDateTimeView::GetDateTime() //获取系统时间 { }
void CDateTimeView::Change() int型转CString型函数 {
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDateTimeDoc))); return (CDateTimeDoc*)m_pDocument;
CDateTimeDoc* pDoc = GetDocument(); time_t curtime=time(0); tm tim =*localtime(&curtime); pDoc->day=tim.tm_mday; pDoc->month=tim.tm_mon+1; pDoc->year=tim.tm_year+1900; pDoc->hour=tim.tm_hour; pDoc->minute=tim.tm_min; pDoc->second=tim.tm_sec;
CDateTimeDoc* pDoc = GetDocument(); pDoc->str_year.Format(\pDoc->str_month.Format(\pDoc->str_day.Format(\pDoc->str_hour.Format(\pDoc->str_minute.Format(\pDoc->str_second.Format(\if(pDoc->month<10) if(pDoc->day<10)
pDoc->str_month=\pDoc->str_day=\
17
}
if(pDoc->hour<10) if(pDoc->minute<10) if(pDoc->second<10)
pDoc->str_hour=\pDoc->str_minute=\pDoc->str_second=\
switch(Week(pDoc->year,pDoc->month,pDoc->day)) {
case 1:pDoc->str3=\星期一\case 2:pDoc->str3=\星期二\case 3:pDoc->str3=\星期三\case 4:pDoc->str3=\星期四\case 5:pDoc->str3=\星期五\case 6:pDoc->str3=\星期六\case 0:pDoc->str3=\星期日\}
void CDateTimeView::RunTime() //时间运行函数 {
CDateTimeDoc* pDoc = GetDocument(); pDoc->second++; if(pDoc->second>=60) { }
if(pDoc->minute>=60) { }
if(pDoc->hour>=24) { }
if((pDoc->month==1||pDoc->month==3||pDoc->month==5||pDoc->month==7||pD
18
pDoc->second=0; pDoc->minute++;
pDoc->minute=0; pDoc->hour++;
pDoc->hour=0; pDoc->day++;
oc->month==8||pDoc->month==10||pDoc->month==12)&&pDoc->day>=32)
{ }
if((pDoc->month==4||pDoc->month==6||pDoc->month==9||pDoc->month==11)&
pDoc->day=1; pDoc->month++;
&pDoc->day>=31)
y>=29)
}
void CDateTimeView::OnInitialUpdate() //计时器设置 { }
void CDateTimeView::OnDestroy() {
{ }
if(pDoc->month==2&&(pDoc->year%4!=0||pDoc->year0==0)&&pDoc->da
pDoc->day=1; pDoc->month++;
{ }
if(pDoc->month==2&&pDoc->day>=30) { }
if(pDoc->month>=13) { }
pDoc->month=1;
pDoc->year++;
pDoc->day=1; pDoc->month++; pDoc->day=1; pDoc->month++;
CView::OnInitialUpdate();
SetTimer(1,50,NULL); //50ms的计时器
CView::OnDestroy();
19