找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2160|回复: 0
打印 上一主题 下一主题
收起左侧

VC6.0编写的一个大屏七段数码时钟程序 纯代码绘制七段笔画

[复制链接]
跳转到指定楼层
楼主
    VC6.0编写的一个大屏七段数码时钟,纯代码绘制七段笔画,使用定时函数读取系统时间,再以七段数码管的形式显示在屏幕上,字体颜色可变,背景颜色可调节。



部分程序如下:        //{{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
}
/绘画数码管分,通过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);
}
//绘画数码管秒,通过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);        
        }
}

  //绘画数码管时,通过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);
}

详细程序请下载附件: LEDClock.7z (3.48 MB, 下载次数: 19)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表