一个简单的时钟程序《VC实现》

 

具体:
1
、首先,我建立一个基于对话框的程序

2、在对话框里建立三个静文本其ID别为 IDC_HOUR IDC_MINUTE IDC_SECOND

3、用MFC三个ID 添加 CString m_hours m_minutes m_seconds

4、然后映射消息WM_TIMER 生成OnTimer() 函数

5Dlg添加一个私有函数CurrentTime() :

void CClockDlg::CurrentTime()

{

    time_t tCurrentTime;

        ///声明

        char szBuffer [ 256 ];

    // 取系统时间

        tCurrentTime = time ( ( time_t* ) NULL );

       

        strftime ( szBuffer, sizeof ( szBuffer ), "%H", localtime ( &tCurrentTime ) );

        m_hours = szBuffer;

        strftime ( szBuffer, sizeof ( szBuffer ), "%M", localtime ( &tCurrentTime ) );

        m_minutes = szBuffer;

        strftime ( szBuffer, sizeof ( szBuffer ), "%S", localtime ( &tCurrentTime ) );

        m_seconds = szBuffer;

 

        // 将各值赋给对话框相ID对应

 

        ( GetDlgItem ( IDC_HOUR ) ) -> SetWindowText ( m_hours );

        ( GetDlgItem ( IDC_MINUTE ) ) -> SetWindowText ( m_minutes );

        ( GetDlgItem ( IDC_SECOND ) ) -> SetWindowText ( m_seconds );

}

6、在 OninitDialog()return TRUE 前面添加:

// 完成定器的安装

int iInstallresult;

iInstallresult=SetTimer(1,1000,NULL);

if(iInstallresult==0)

{

        MessageBox("fail to install the timer!");

}

else

        CurrentTime();

7、在OnTimer()里添加

CurrentTime();

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值