资源描述:
《模拟时钟源代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、voidCTest13_4Doc::m_TickAdd(){this->m_sec++;if(this->m_sec==60){this->m_min++;this->m_sec=0;}if(this->m_min==60){this->m_hour++;this->m_min=0;}if(this->m_hour>=12){this->m_hour-=12;}}voidCTest13_4Doc::M_MoveClockHands(){intpx,py;doubledegree;//设置秒针的终点坐标degree=this->m_sec*6-
2、90;px=cos((degree/180.0)*PI)*sLen+250;py=sin((degree/180)*PI)*sLen+250;this->m_secEndPoint.x=px;this->m_secEndPoint.y=py;//设置分针的终点坐标degree=this->m_min*6-90;px=cos((degree/180.0)*PI)*mLen+250;py=sin((degree/180)*PI)*mLen+250;this->m_minEndPoint.x=px;this->m_minEndPoint.y=py;
3、//设置时针的终点坐标degree=this->m_hour*30-90;px=cos((degree/180.0)*PI)*hLen+250;py=sin((degree/180.0)*PI)*hLen+250;this->m_hourEndPoint.x=px;this->m_hourEndPoint.y=py;}BOOLCTest13_4Doc::OnNewDocument(){if(!CDocument::OnNewDocument())returnFALSE;//TODO:addreinitializationcodeherethi
4、s->m_Rect=CRect(100,100,400,400);this->m_org=this->m_Rect.CenterPoint();this->m_centerRect=CRect(m_Rect.TopLeft().x+140,m_Rect.TopLeft().y+140,m_Rect.BottomRight().x-140,m_Rect.BottomRight().y-140);CTimetime=CTime::GetCurrentTime();this->m_hour=time.GetHour();this->m_min=ti
5、me.GetMinute();this->m_sec=time.GetSecond();//设置时钟指针的终点位置//this->M_MoveClockHands();//设置指针的长度hLen=80;mLen=100;sLen=120;//(SDIdocumentswillreusethisdocument)returnTRUE;}voidCTest13_4View::OnDraw(CDC*pDC){CTest13_4Doc*pDoc=GetDocument();ASSERT_VALID(pDoc);SetTimer(0,1000,NULL
6、);CPen*oldPen,*cPen;CBrush*oldBrush,*cBrush;//画出大的圆cPen=newCPen(PS_SOLID,3,RGB(255,132,123));cBrush=newCBrush(RGB(123,132,123));oldPen=pDC->SelectObject(cPen);oldBrush=pDC->SelectObject(cBrush);pDC->Ellipse(pDoc->m_Rect);pDC->SelectObject(oldPen);pDC->SelectObject(oldBrush)
7、;//画出中心的一个圆cBrush=newCBrush(RGB(255,132,123));pDC->SelectObject(cBrush);pDC->Ellipse(pDoc->m_centerRect);pDC->SelectObject(oldBrush);//得到矩形的另个点,画出四个分线cPen=newCPen(PS_SOLID,2,RGB(255,222,123));oldPen=pDC->SelectObject(cPen);CPointtl=pDoc->m_Rect.TopLeft();CPointbr=pDoc->m_Re
8、ct.BottomRight();pDC->MoveTo((br.x+tl.x)/2,tl.y);pDC->LineTo((br.x+tl.x)/2,tl.y+20