部分程序如下: //{{AFX_DATA(CLEDClockDlg)
enum { IDD = IDD_LEDCLOCK_DIALOG };
CDigitalClock m_clock;
int m_green;
UINT m_hour;
UINT m_minute;
UINT m_second;
int m_blue;
int m_red;
int m_shour;
int m_sminute;
int m_ssecond;
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_red=0;
m_green=255;
m_blue=0;
m_clock.SetBkColor(RGB(0,0,0));
m_clock.SetTextColor(RGB( m_red,m_green,m_blue));
CTime time=CTime::GetCurrentTime();
m_shour=time.GetHour();
m_sminute=time.GetMinute();
m_ssecond=time.GetSecond();
UpdateData(false);
SetTimer(1,1000,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
/繪畫數(shù)碼管分,通過ADD Member Function...添加
void CDigitalClock::DrawMinute()
{
int nLeft=m_nXmargin+3*m_nWidth+m_nSpace;
if (m_nMinute<10)
{
DrawSingleNumber(0,nLeft);
nLeft+=m_nWidth+m_nSpace;
DrawSingleNumber(m_nMinute,nLeft);
}
else
{
TCHAR c[10]={0};
_itoa(m_nMinute,c,10);
int num1=c[0]-48;
int num2=c[1]-48;
DrawSingleNumber(num1,nLeft);
nLeft+=m_nWidth+m_nSpace;
DrawSingleNumber(num2,nLeft);
}
nLeft+=m_nWidth;
Draw2Dot(nLeft);
}
//繪畫數(shù)碼管秒,通過ADD Member Function...添加
void CDigitalClock::DrawSecond()
{
int nLeft=m_nXmargin+6*m_nWidth+2*m_nSpace;
if (m_nSecond<10)
{
DrawSingleNumber(0,nLeft);
// nLeft+=(int)(1.4*m_nWidth);
nLeft+=m_nWidth+m_nSpace;
DrawSingleNumber(m_nSecond,nLeft);
}
else
{
TCHAR *c=new TCHAR[10];
_itoa(m_nSecond,c,10);
int num1=c[0]-48;
int num2=c[1]-48;
DrawSingleNumber(num1,nLeft);
nLeft+=m_nWidth+m_nSpace;
DrawSingleNumber(num2,nLeft);
}
}
//繪畫數(shù)碼管時,通過ADD Member Function...添加
void CDigitalClock::DrawHour()
{
int nLeft=m_nXmargin;
if (m_nHour<10)
{
DrawSingleNumber(0,nLeft);
nLeft+=m_nWidth+m_nSpace;
DrawSingleNumber(m_nHour,nLeft);
}
else
{
TCHAR *c=new TCHAR[10];
_itoa(m_nHour,c,10);
int num1=c[0]-48;
int num2=c[1]-48;
DrawSingleNumber(num1,nLeft);
nLeft+=m_nWidth+m_nSpace;
DrawSingleNumber(num2,nLeft);
}
nLeft+=m_nWidth;
Draw2Dot(nLeft);
}
void CLEDClockDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CTime time=CTime::GetCurrentTime();
UpdateData(true);
int nHour=time.GetHour();
int nMinute=time.GetMinute();
int nSecond=time.GetSecond();
m_second++;
if(m_second>59)
{
m_second=0;
m_minute++;
if(m_minute>59)
{
m_minute=0;
m_hour++;
if(m_hour>23)
{
m_hour=0;
}
}
}