内容转载自 https://blog.csdn.net/my_angle2016/article/details/107957105
#define KB 1024 #define MB (1024*KB) #define GB (1024*MB) void CDemoDlg::OnTest() { int nNum1 = GetDlgItemInt(IDC_NUM1); CString strNum2 = _T(""); //转换成GB if (nNum1 > GB) { strNum2.Format(_T("%0.2fGB"), (double)nNum1 / GB); } //转换成MB else if (nNum1 > MB) { strNum2.Format(_T("%0.2fMB"), (double)nNum1 / MB); } //转换成KB else if (nNum1 > KB) { int n = nNum1 / KB; strNum2.Format(_T("%0.2fKB"), (double)nNum1 / KB); } else { strNum2.Format(_T("%dByte"), nNum1); } SetDlgItemText(IDC_NUM2, strNum2); }
获得文件大小用 CFile::GetStatus
//获得文件大小 CFileStatus status; CFile::GetStatus(file_path, status); int nNum1 = 0; CString strNum2; nNum1 = nNum1 + status.m_size;
阿飞
2021年10月24日