char crDrv[3]; CStringArray strArray; _ULARGE_INTEGER n64TotalNumberOfBytes, n64TotalNumberOfFreeBytes; __int64 n64TotalFree = 0,n64TotalSpace = 0; float fTotalFree,fTotalSpace,fTempFree,fTempTotal; ULONG lTotalFree = 0,lTotalSpace = 0, lTempFree = 0,lTempTotal = 0; CString strInfo; BOOL bSuccess;
for(int n=2;n<=25;n++) { CString str; str.Format(“%c:\“,n+’A’); strcpy(crDrv,str); UINT nDrvType = GetDriveType(crDrv); switch(nDrvType) { case DRIVE_FIXED: { strArray.Add(crDrv); break; } default: { break; } } }
for(n = 0;n < strArray.GetSize();n ++) { bSuccess = SHGetDiskFreeSpace(strArray.GetAt(n), NULL,&n64TotalNumberOfBytes;, &n64TotalNumberOfFreeBytes;); n64TotalSpace += n64TotalNumberOfBytes.QuadPart; n64TotalFree += n64TotalNumberOfFreeBytes.QuadPart;
lTempTotal = (ULONG)(n64TotalNumberOfBytes.QuadPart/1024); lTempFree = (ULONG)(n64TotalNumberOfFreeBytes.QuadPart/1024); fTempTotal = (float)lTempTotal; fTempTotal = fTempTotal/1024/1024; fTempFree = (float)lTempFree; fTempFree = fTempFree/1024/1024;
strInfo.Format(“%s 容量: %4.2fGB,可用空间: %4.2fGB.”, strArray.GetAt(n),fTempTotal,fTempFree); AfxMessageBox(strInfo); }
lTotalSpace = (ULONG)(n64TotalSpace/1024); lTotalFree = (ULONG)(n64TotalFree/1024); fTotalSpace = (float)lTotalSpace; fTotalSpace = fTotalSpace/1024/1024; fTotalFree = (float)lTotalFree; fTotalFree = fTotalFree/1024/1024;
strInfo.Format(“总容量: %4.2fGB,总共可用空间: %4.2fGB.”, fTotalSpace,fTotalFree); AfxMessageBox(strInfo);