標(biāo)題: VC6.0編寫的一個大屏七段數(shù)碼時鐘程序 純代碼繪制七段筆畫 [打印本頁]

作者: xzk123    時間: 2022-5-4 08:10
標(biāo)題: VC6.0編寫的一個大屏七段數(shù)碼時鐘程序 純代碼繪制七段筆畫
    VC6.0編寫的一個大屏七段數(shù)碼時鐘,純代碼繪制七段筆畫,使用定時函數(shù)讀取系統(tǒng)時間,再以七段數(shù)碼管的形式顯示在屏幕上,字體顏色可變,背景顏色可調(diào)節(jié)。



部分程序如下:        //{{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;


/////////////////////////////////////////////////////////////////////////////
// CLEDClockDlg message handlers

BOOL CLEDClockDlg::OnInitDialog()
{
        CDialog::OnInitDialog();

        // Add "About..." menu item to system menu.

        // IDM_ABOUTBOX must be in the system command range.
        ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
        ASSERT(IDM_ABOUTBOX < 0xF000);

        CMenu* pSysMenu = GetSystemMenu(FALSE);
        if (pSysMenu != NULL)
        {
                CString strAboutMenu;
                strAboutMenu.LoadString(IDS_ABOUTBOX);
                if (!strAboutMenu.IsEmpty())
                {
                        pSysMenu->AppendMenu(MF_SEPARATOR);
                        pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
                }
        }

        // 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;
                 }
           }
        }
         
    if(m_blue==0)
        {
                if(m_red<255)
                {
                        m_red+=15;
                }
        }
        
         if(m_red==255)
        {
                if(m_green>0)
                {
                        m_green-=15;
        }
        }
         if(m_green==0)
        {
                if(m_blue<255)
                {
                        m_blue+=15;
        }
        }
if(m_blue==255)
        {
                if(m_red>0)
                {
                        m_red-=15;
                }
        }               
         if(m_red==0)
        {
                if(m_green<255)
                {
                        m_green+=15;
                }
        }
    if(m_green==255)
        {
                if(m_blue>0)
                {
                    m_blue-=15;
                }
        }               
        m_clock.SetTextColor(RGB(m_red,m_green,m_blue));
        m_clock.SetClock(nHour,nMinute,nSecond);

        UpdateData(false);
        CDialog::OnTimer(nIDEvent);
}

詳細(xì)程序請下載附件: LEDClock.7z (3.48 MB, 下載次數(shù): 19)





歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1