您的位置:首页 > 其它

MFC 的几个常用函数,用来计算文件大小,下载速度,转换时间的

2011-11-27 18:27 537 查看
//获取文件的大小,并以KB 或 MB 来表示
CString GetFileSize(LONG size)
{
CString _size;
//判断大小有没有超过1
if (size<(1024*1024))
{
_size.Format("%.2lfKB",size/1024.0);
}else if(1024*1024*1024)
{
_size.Format("%.2lfMB",(size/1024.0)/1024.0);
}else
{
_size.Format("%.2lfGB",(size/1024.0/1024.0)/1024.0);
}
return _size;
}
//获取下载速度的字符串
CString GetFileTranSpeed(DWORD size,DWORD time)
{
CString _speed;
//判断时间是否为0
if (time>0){
if (size/1024*1000.0/time<1024)
{
_speed.Format("%.2lfKB/s",size/1024*1000.0/time);
}else
{
_speed.Format("%.2lfMB/s",(size/1024)*1000.0/time);
}
}else
{
return _speed = "0KB/s";
}
return _speed;
}
//获取时间的字符串
CString GetTimeFormatStr(LONG time)
{
CString _time;
int hh = time/3600;
int mm = (time-hh*3600)/60;
int ss =  time%60;
_time.Format("%d%d:%d%d:%d%d",hh/10,hh%10,mm/10,mm%10,ss/10,ss%10);
return _time;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐