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;
}