写入注册表时间计算程序运行时间例子

int RegOperate::GetLastOneClickTime(CString& strOut)
{
    int ntype;
    CheckRegistryKeyAndSetDefault(SOFT_IN_REG_PATH, _T("写入注册表的文件名"), 1);//1表示不存在就写入空值
    LONG nret;
    HKEY hkey;
    int nResult;
    nResult = RegOpenKeyEx(HKEY_CURRENT_USER, SOFT_IN_REG_PATH, 0, KEY_ALL_ACCESS, &hkey);
    if (nResult != ERROR_SUCCESS)
    {
        return 2;
    }
    TCHAR szVal[MAX_PATH] = { 0 };
    DWORD cnum = MAX_PATH;
    nret = RegQueryValueEx(hkey, _T("写入注册表的文件名"), NULL, NULL, (LPBYTE)szVal, &cnum);  //拿到注册表的时间值
    RegCloseKey(hkey);
    CString tempstr = szVal;
    if (tempstr == _T("")) 
    {
        strOut=TEXT("You have not maked an overall scanning!");
        return 0;//返回0表示还没进行过
    }
    int nYear = _wtoi(tempstr.Mid(0, 4));
    int nMonth = _wtoi(tempstr.Mid(5, 2));
    int nDay = _wtoi(tempstr.Mid(8, 2));
    int nHour = _wtoi(tempstr.Mid(11, 2));
    int nMin = _wtoi(tempstr.Mid(14, 2));
    int nSec = _wtoi(tempstr.Mid(17, 2));

    CTime oldTime(nYear, nMonth, nDay, nHour, nMin, nSec);
    CTime nowTime = CTime::GetCurrentTime();
    CTimeSpan ts = nowTime - oldTime;

    LONGLONG time;

    if (ts.GetTotalMinutes() > 60) //拆分计算
    {
        if (ts.GetTotalHours() >= 24)
        {
            time = ts.GetDays();
            ntype = 1;//_T("Days");
            strOut.Format(TEXT("%d Days"), (int)time);
        }
        else
        {
            time = ts.GetHours();
            ntype = 2;//_T("Hours");
            strOut.Format(TEXT("%d Hours"), (int)time);
        }
    }
    else
    {
        time = ts.GetTotalMinutes();
        ntype = 3;//_T("Minutes");
        strOut.Format(TEXT("%d Minutes"), (int)time);
    }
    tempstr.Format(_T("%d"), (int)time);

    return ntype;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值