从对话框开启时一个Static Text 就开始计时, 形式为 00:00:00
谁能帮我把代码详细实现 ,感激不尽!

解决方案 »

  1.   

    http://www.vckbase.com/document/viewdoc/?id=1166
      

  2.   

    第一步:创建一个基于对话框的工程
    第二步:在对话框资源上增加一个STATIC控件,ID为IDC_STATIC_TIME,Caption为空
    第三步:在类CTimeDlg上增加消息处理器:WM_TIMER
    第四步:在函数OnInitDialog中增加函数:SetTimer(1, 1000, NULL);
    第五步:在函数OnTimer中添加代码:SYSTEMTIME tm;
    GetLocalTime(&tm);
    CString str;
    str.Format("%2d:%2d:%2d", tm.wHour, tm.wMinute, tm.wSecond);
    GetDlgItem(IDC_STATIC_TIME)->SetWindowText(str);
      

  3.   

    精度要求不高的话,用SetTimer即可!CYourDlg::OnTimer(....)
    {
        CTime   tm = CTime::GetCurrentTime();
        CString szTips;    szTips.Format(_T("%02d:%02d:%02d"),
                tm.GetHour(),
                tm.GetMinute(),
                tm.GetSecond());
        GetDlgItem(IDC_STATIC_CLOCK)->SetWindowText(szTips);
    }
      

  4.   

    第一步:创建一个基于对话框的工程
    第二步:在对话框上增加static控件,ID为IDC_STATIC_TIME,Caption为空
    第三步:增加消息处理器:WM_TIMER----OnTimer
    第四步:在OnInitDialog函数中增加代码:SetTimer(1, 1000, NULL);
    SYSTEMTIME tm;
    GetLocalTime(&tm);
    CString str;
    str.Format("%02d:%02d:%02d", tm.wHour, tm.wMinute, tm.wSecond);
    GetDlgItem(IDC_STATIC_TIME)->SetWindowText(str);第五步:在OnTimer函数中增加代码:if(1==nIDEvent)
    {
        SYSTEMTIME tm;
        GetLocalTime(&tm);
        CString str;
        str.Format("%02d:%02d:%02d", tm.wHour, tm.wMinute, tm.wSecond);
        GetDlgItem(IDC_STATIC_TIME)->SetWindowText(str);
    }