2 a1060561907 a1060561907 于 2016.09.23 00:19 提问

mfc硬盘容量怎么获取全部
char    DriveString[256];char   *pDrive =NULL;GetLogicalDriveStrings(sizeof(DriveString), DriveString);pDrive = DriveString;if (GetDiskFreeSpaceEx(pDrive, (PULARGE_INTEGER)&HDFreeSpace, (PULARG

3个回答

caozhy
caozhy   Ds   Rxr 2016.09.23 00:23
 void CGetSpaceDlg::OnBtngs() 
{
 // TODO: Add your control notification handler code here
 UpdateData(TRUE);
 CString strAllInfo;

    //获得磁盘空间信息
    ULARGE_INTEGER FreeAv,TotalBytes,FreeBytes;
    if (GetDiskFreeSpaceEx(m_fpath,&FreeAv,&TotalBytes,&FreeBytes)) //m_fpath是你的盘符
    {
        //格式化信息,并显示出来
        CString strTotalBytes,strFreeBytes;
        //strTotalBytes.Format("Total:%u bytes",TotalBytes.QuadPart);
        //strFreeBytes.Format("Left:%u bytes",FreeBytes.QuadPart);

        strTotalBytes.Format("Total:%luM",TotalBytes.QuadPart/(ULONGLONG)(1024*1024));
        strFreeBytes.Format("Left:%luG",FreeBytes.QuadPart/(ULONGLONG)(1024*1024*1024));
        strAllInfo.Format("Info:[%s] %s %s \nU can use %luG",m_fpath,strTotalBytes,strFreeBytes, FreeAv.QuadPart/(ULONGLONG)(1024*1024*1024));/* 单位为G */
  MessageBox(strAllInfo);
 }
}
caozhy
caozhy   Ds   Rxr 2016.09.23 00:23

获得计算机所有驱动器

 void CDiskInfoDlg::FindAllDrivers()
{
   CComboBox* Driver=(CComboBox*)GetDlgItem(IDC_DRIVER);
   DWORD dwwNumBytesForDriverStrings;//实际存储驱动器号的字符串长度
   HANDLE hHeap;
   LPSTR lp;
   CString strLogdriver;
   //获得实际存储驱动器号的字符串长度
   dwwNumBytesForDriverStrings=GetLogicalDriveStrings(0,NULL)*sizeof(TCHAR);
   //如果字符串不为空,则表明有正常的驱动器存在
   if(dwwNumBytesForDriverStrings!=0)
   {
      hHeap=GetProcessHeap();
   //分配字符串空间
   lp=(LPSTR)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,dwwNumBytesForDriverStrings);
   //获得标明所有驱动器的字符串
   GetLogicalDriveStrings(HeapSize(hHeap,0,lp),lp);
   //将驱动器一个一个的放到下拉框中
   while(*lp!=0)
   {
    Driver->AddString(lp);
         lp=_tcschr(lp,0)+1;
     }
   }
   else
    AfxMessageBox("Can't User The Function GetLogicalDriveStrings!");
}
a1060561907
a1060561907   2016.09.23 00:22

每次只获取到单个盘的容量,怎么获取全部

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!