Win32API之GetProcessTimes范例


API都会调用,放这个例子上来是想说一下程序运行时间,内核时间以及用户时间是怎么一回事。
部分关键的代码:

GetProcessTimes(hProcess, &ftCreation, &ftExit, &ftKernel, &ftUser);

timeCreation = ftCreation;

strData.Format("Created at %02d:%02d:%02d", timeCreation.GetHour(), 
               timeCreation.GetMinute(), timeCreation.GetSecond());

timeDiff = timeNow - timeCreation;
strData.Format("Elapsed time = %ud %uh %um %us", timeDiff.GetDays(), 
               timeDiff.GetHours(), timeDiff.GetMinutes(), 
               timeDiff.GetSeconds());

FileTimeToSystemTime(&ftKernel, &stKernel);
strData.Format("Time in kernel mode = %uh %um %us", stKernel.wHour,
               stKernel.wMinute, stKernel.wSecond);

下载 [download id=”17″]
via codeproject.com
-EOF-

发表评论

电子邮件地址不会被公开。 必填项已用*标注