资源描述:
《vc++课程设计--基于mfc的模拟时钟》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、计科2011级VC++课程设计实验报告题目:基于MFC的模拟时钟班级:计科1104班学号:1108030429姓名:张宝龙日期:2014/1/7课程设计实验报告1、题目:基于MFC的模拟时钟2、编程要点:制作时钟的过程中,首先给时钟创建一个基类CClockElement,还需要派生类CClockBackground,CClockHourHand,CClockMinHand,CClockSecHand分别控制时钟的背景,时钟的时针,分针,秒针。3、实现过程:(1)工程、风格、控件与变量表本时钟是基本对话框的时钟,界面简约,便于使用。控件控件名控件类型Clock
2、静态文本变量表变量名类型m_crMainCOLORREFm_crOtherCOLORREFm_tmCurCTimem_rcRegionCRectm_nRadiusintm_clockBKCClockBackgroundm_clockHourCClockHourHandm_clockMinCClockMinHandm_clockSecCClockSecHandm_rcClientCRectm_ClockCClockEX(2)主要功能程序代码CClockBackground::CClockBackground(){//为时钟背景定义默认的颜色设置m_crMain
3、=RGB(0,0,255);m_crOther=RGB(0,255,0);}voidCClockBackground::Draw(CDC*pDC){//设置准备环境CPenpenMain(PS_SOLID,1,m_crMain),penOther(PS_SOLID,1,m_crOther);CBrushbrMain(m_crMain),brOther(m_crOther);CPen*pOldPen=pDC->SelectObject(&penOther);CBrush*pOldBrush=pDC->SelectObject(&brMain);CPointpt
4、Center=m_rcRegion.CenterPoint();intnRadius=m_nRadius-8;for(inti=0;i<60;i++){CPointptEnd=ptCenter;ptEnd.Offset((int)(nRadius*sin(2*PI*(i%60)/60)),(int)(-nRadius*cos(2*PI*(i%60)/60)));CRectrcDot(-2,-2,2,2);rcDot.OffsetRect(ptEnd);pDC->Ellipse(rcDot);}//绘制12个小方框,表示12个正点pDC->SelectObje
5、ct(&penMain);pOldBrush=pDC->SelectObject(&brOther);for(i=0;i<12;i++){CPointptEnd=ptCenter;doublefRadian=2*PI*(i%12)/12;ptEnd.Offset((int)(nRadius*sin(fRadian)),(int)(-nRadius*cos(fRadian)));CRectrcDot(-3,-3,3,3);rcDot.OffsetRect(ptEnd);pDC->Rectangle(rcDot);}//huanyuan设备环境pDC->Sele
6、ctObject(pOldPen);pDC->SelectObject(pOldBrush);}CClockHourHand::CClockHourHand(){//定义默认颜色m_crMain=RGB(0,0,128);m_crOther=RGB(128,128,0);}voidCClockHourHand::Draw(CDC*pDC){//设置准备环境CPenpenMain(PS_SOLID,1,m_crMain),penOther(PS_SOLID,1,m_crOther);CBrushbrMain(m_crMain),brOther(m_crOthe
7、r);CPen*pOldPen=pDC->SelectObject(&penOther);CBrush*pOldBrush=pDC->SelectObject(&brMain);//确定当前指针的弧度intnTime=(m_tmCur.GetHour()%12)*3600;nTime+=m_tmCur.GetMinute()*60;nTime+=m_tmCur.GetSecond();doublefRadian=2*PI*nTime/3600/12;//确定绘制菱形指针所需的四个角的坐标CPointptDiamond[4];for(inti=0;i<4;i+
8、+){ptDiamond[i]=m_rcRegion