怎么样得到硬盘当中的分区情况,就是有哪些盘c:\;d:\;e:\……

解决方案 »

  1.   

    DWORD GetLogicalDriveStrings(
      DWORD nBufferLength,  // size of buffer
      LPTSTR lpBuffer       // pointer to buffer for drive strings
    );
      

  2.   

    void CShowDiskDlg::GetAllDisk()
    {
    char buf[BUFSIZ] =  { 0 };
    int drivers(0);
    char *pBuf;
    drivers = ::GetLogicalDriveStrings(MAX_PATH, buf);
    if (!drivers) 
    {
    return;
    } pBuf = buf;
    m_lstDisk.InsertItem(m_lstDisk.GetItemCount(), pBuf);
    SetDiskPlace(pBuf);
    while (*(pBuf) != NULL)
    {
    for (;;) 
    {
    if (*(++pBuf) ==  NULL)
    {
    if (*(++pBuf) == NULL)
    {
    return;
    }
    m_lstDisk.InsertItem(m_lstDisk.GetItemCount(), pBuf);
    SetDiskPlace(pBuf);
    }
    break;
    }
    }
    }
      

  3.   

    void CShowDiskDlg::GetAllDisk()
    {
    char buf[BUFSIZ] =  { 0 };
    int drivers(0);
    char *pBuf;
    drivers = ::GetLogicalDriveStrings(MAX_PATH, buf);
    if (!drivers) 
    {
    return;
    } pBuf = buf;
    m_lstDisk.InsertItem(m_lstDisk.GetItemCount(), pBuf);
    SetDiskPlace(pBuf);
    while (*(pBuf) != NULL)
    {
    for (;;) 
    {
    if (*(++pBuf) ==  NULL)
    {
    if (*(++pBuf) == NULL)
    {
    return;
    }
    m_lstDisk.InsertItem(m_lstDisk.GetItemCount(), pBuf);
    SetDiskPlace(pBuf);
    }
    break;
    }
    }
    }
      

  4.   

    CArray<LOGDRIVEINFO, LPCTSTR> arrLogicalDrives;
    CString Type[7];
    int m_iItemcount=0
    CString strName[100],strValu[100];
    Type[0] = _TEXT("The drive type cannot be determined.");
    Type[1] = _TEXT("The root path is invalid. For example, no volume is mounted at the path.");
    Type[2] = _TEXT("The disk can be removed from the drive.");
    Type[3] = _TEXT("The disk cannot be removed from the drive.");
    Type[4] = _TEXT("The drive is a remote (network) drive.");
    Type[5] = _TEXT("The drive is a CD-ROM drive.");
    Type[6] = _TEXT("The drive is a RAM disk.");const int LOGDRIVEBUFSIZE = 1024;
    LPTSTR lpszzLogicalDrives = new TCHAR[LOGDRIVEBUFSIZE];
    ::ZeroMemory(lpszzLogicalDrives, LOGDRIVEBUFSIZE * sizeof(TCHAR));
    ::GetLogicalDriveStrings(LOGDRIVEBUFSIZE, lpszzLogicalDrives);for(LPTSTR lpsz=lpszzLogicalDrives;*lpsz!=0;lpsz+=::_tcslen(lpsz)+1)
    {
        TCHAR szLogicalDrive[4] = { 0 };
        ::_tcsnccpy(szLogicalDrive, lpsz, ::_tcslen(lpsz)-1);
        int nIndex = arrLogicalDrives.Add(szLogicalDrive);
        arrLogicalDrives[nIndex].m_bInfoValid = ::GetVolumeInformation  (lpsz,arrLogicalDrives[nIndex].m_sVolumeName.GetBuffer(_MAX_PATH), _MAX_PATH,&arrLogicalDrives[nIndex].m_dwVolumeSerialNumber,&arrLogicalDrives[nIndex].m_dwMaxNameLength,&arrLogicalDrives[nIndex].m_dwFileSystemFlags,arrLogicalDrives[nIndex].m_sFileSystemName.GetBuffer(_MAX_PATH), _MAX_PATH);
    arrLogicalDrives[nIndex].m_sVolumeName.ReleaseBuffer();
    arrLogicalDrives[nIndex].m_sFileSystemName.ReleaseBuffer();
    arrLogicalDrives[nIndex].m_nDriveType = ::GetDriveType(lpsz);
       if(arrLogicalDrives[nIndex].m_nDriveType == DRIVE_FIXED||arrLogicalDrives[nIndex].m_nDriveType==DRIVE_CDROM || arrLogicalDrives[nIndex].m_nDriveType == DRIVE_RAMDISK)
       {
            ::GetDiskFreeSpace(lpsz, &arrLogicalDrives[nIndex].m_nSectorsPerCluster,&arrLogicalDrives[nIndex].m_nBytesPerSector,&arrLogicalDrives[nIndex].m_nFreeClusters, &arrLogicalDrives[nIndex].m_nClusters);
        } 
        strName[m_iItemcount] = _TEXT("logic-"); 
        strName[m_iItemcount] += _TEXT(lpsz);
        strValu[m_iItemcount++].Format(Type[arrLogicalDrives [nIndex].m_nDriveType]);
    }strName[]输出项目
    strValu[]输出值
      

  5.   

    先GetLogicalDrive()
    然后GetDriveType()
      

  6.   

    CHAR SysDir[128];
    int strLen=0;
    int m_pos,i;
    CString strSysDir,strTempDirver;
    strTempDirver="";
    strLen=GetLogicalDriveStrings(128,SysDir);
    if(strLen!=0)
    {
    for(i=0;i<strLen;i++)
    {
    if(SysDir[i]=='\0')
    SysDir[i]=' ';
    }
    } strSysDir.Format("%s",SysDir);
    m_pos=strSysDir.Find(":",1);
    while(m_pos!=-1)
    {
    strTempDirver.Format("%s",strSysDir.Left(m_pos+1));
    if(strTempDirver!="C:")
    {
    OpenExistFile(strTempDirver);
    }
    strSysDir.Format("%s\n",strSysDir.Right(strSysDir.GetLength()-m_pos-3)); 
    m_pos=strSysDir.Find(":",1);
    }