判断驱动器的类型 
  使用API函数GetDriveType能判断一个驱动器的类型,该函数返回一个int型的值,当返回值为2时,是软盘;为3时,是硬盘;为4时,是网络映射盘;为5时,是光驱;为6时,是 RAM 磁盘;为其它值时,是非法的盘符。这个API函数包含在winbase.h头文件中,首先在程序头部加上语句:include <winbase.h>包含头文件,然后在程序中加入以下代码就可以判断驱动器的类型:int drv;
//这里的"C:\\"为要判断的盘符
drv=GetDriveType("C:\\");
switch (drv) //判断drv的值
{
case 2 : //DRIVE_REMOVABLEShowMessage("软盘");
break;case 3 : //DRIVE_FIXEDShowMessage("硬盘");
break;case 4 : //DRIVE_REMOTEShowMessage("网络映射盘");
break;case 5 : //DRIVE_CDROMShowMessage("光驱");
break;case 6 : //DRIVE_RAMDISKShowMessage("RAM 磁盘");
break;default :ShowMessage("这个磁盘不存在!");
break;}注:case语句后的数值也可以用注释后的常数替换。如2可用常数 DRIVE_REMOVABLE 来替换。 
   
 

解决方案 »

  1.   


      Platform SDK: Files and I/O 
    GetLogicalDrives
    The GetLogicalDrives function retrieves a bitmask representing the currently available disk drives. DWORD GetLogicalDrives(VOID);
    Parameters
    This function has no parameters. Return Values
    If the function succeeds, the return value is a bitmask representing the currently available disk drives. Bit position 0 (the least-significant bit) is drive A, bit position 1 is drive B, bit position 2 is drive C, and so on. If the function fails, the return value is zero. To get extended error information, call GetLastError.Requirements 
      Windows NT/2000: Requires Windows NT 3.1 or later.
      Windows 95/98: Requires Windows 95 or later.
      Header: Declared in Winbase.h; include Windows.h.
      Library: Use Kernel32.lib.See Also
    File I/O Overview, File I/O Functions, GetLogicalDriveStrings Built on Friday, May 12, 2000Requirements 
      Windows NT/2000: Requires Windows NT 3.1 or later.
      Windows 95/98: Requires Windows 95 or later.
      Header: Declared in Winbase.h; include Windows.h.
      Library: Use Kernel32.lib.
    See Also
    File I/O Overview, File I/O Functions, GetLogicalDriveStrings 
      

  2.   

    GetLogicalDrives
    GetLogicalDriveStrings
      

  3.   

    多谢各位的支持!问题已经解决了!
    就我的问题而言,用GetDriverType 和 GetLogicalDriveStrings 都能解决
    问题,后者更简便一点!!
    多谢 strip(阿飞) 和ccnuxjg(钢铁就是这样炼成的!) !
    其他朋友也给予了提示,能从中学到东西!!