CDC *pDC=this->GetDC(); CRect rc(100,100,390,390); // GetClientRect( &rc ); int xStart = (rc.right+rc.left)/2; int yStart = (rc.bottom+rc.top)/2; CTime time = CTime::GetCurrentTime(); CString strDigits; int i,x,y; CSize size; CPen Pen(PS_SOLID,5,RGB(0,0,0)); CPen *pOldPen=pDC->SelectObject(&Pen); pDC->Ellipse(rc.left+5,rc.top+5,rc.right-5,rc.bottom-5); double Radians; pDC->SetTextColor(RGB(0,0,0)); for(i=1; i<=12; i++){ strDigits.Format(_T("%d"),i); size =pDC->GetTextExtent(strDigits,strDigits.GetLength()); Radians=(double)i*6.28/12.0;//弧度数 x=xStart-(size.cx/2)+ (int)((double)((rc.right-rc.left-30)/2)*sin(Radians)); y=yStart-( size.cy/2)- (int)((double)((rc.right-rc.left-30)/2)*cos(Radians)); pDC->ExtTextOut( x, y, ETO_CLIPPED ,NULL,strDigits,strDigits.GetLength(),NULL ); } Radians = (double)time.GetHour()+(double)time.GetMinute()/60.0+ (double)time.GetSecond()/3600.0; Radians *= 6.28/12.0; CPen HourPen(PS_SOLID,5,RGB(0,0,0)); pDC->SelectObject(&HourPen); pDC->MoveTo(xStart,yStart); pDC->LineTo(xStart+(int)((double)((rc.right-rc.left-30)/2/3) *sin(Radians)), yStart-(int)((double)(((rc.bottom-rc.top-30)/2)/3)*cos(Radians))); Radians=(double)time.GetMinute()+(double)time.GetSecond()/60.0; Radians*=6.28/60.0; CPen MinutePen(PS_SOLID,3,RGB(0,0,0)); pDC->SelectObject(&MinutePen); pDC->MoveTo(xStart,yStart); pDC->LineTo(xStart+(int)((double)(((rc.right-rc.left-30)/2*2)/3)*sin(Radians)), yStart-(int)((double)((((rc.bottom-rc.top-30)/2)*2)/3)*cos(Radians))); Radians=(double)time.GetSecond(); Radians*=6.28/60.0; CPen SecondPen(PS_SOLID,1,RGB(0,0,0)); pDC->SelectObject(&SecondPen); pDC->MoveTo(xStart,yStart); pDC->LineTo(xStart+(int)((double)(((rc.right-rc.left-30)/2*4)/5)*sin(Radians)), yStart-(int)((double)((((rc.bottom-rc.top-30)/2)*4)/5)*cos(Radians))); pDC->SelectObject(pOldPen);