如题
在线……

解决方案 »

  1.   


    #include "stdafx.h"
    #include "resource.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endifusing namespace std; // for string class// 下面是一个GetDriveType返回码与人可读字符串的迷你对照表
    //
    struct {
       UINT type;        // GetDriveType返回码类型
       LPCSTR name;      // ascii 名称
    } DriveTypeFlags [] = {
       { DRIVE_UNKNOWN,     "未知" },
       { DRIVE_NO_ROOT_DIR, "无效路经" },
       { DRIVE_REMOVABLE,   "可移动" },
       { DRIVE_FIXED,       "固定" },
       { DRIVE_REMOTE,      "网络驱动器" },
       { DRIVE_CDROM,       "CD-ROM" },
       { DRIVE_RAMDISK,     "随机存取磁盘" },
       { 0, NULL},
    };int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
    {
       if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) {
          cerr << _T("Fatal Error: MFC initialization failed") << endl;
          return -1;
       }   // 获取逻辑驱动器字符串- a:\b:\c:\... 等.
       // 还可以用GetLogicalDrives 以位图形式代替字符串形式获取信息   TCHAR buf[100];
       DWORD len = GetLogicalDriveStrings(sizeof(buf)/sizeof(TCHAR),buf);   // 显示每个驱动器的信息
       //
       string msg = "Logical Drives:\n";  // STL string
       for (TCHAR* s=buf; *s; s+=_tcslen(s)+1) {
          LPCTSTR sDrivePath = s;
          msg += sDrivePath;
          msg += " ";      // GetDriveType 获取枚举值,如DRIVE_UNKNOWN等.
          //
          UINT uDriveType = GetDriveType(sDrivePath);// 查找驱动器类型。在此我用了表(结构数组)来进行查找处理,过于繁琐了一些,
    // 但既然uDriveType 的值是连续的。
    // 我可以用DriveTypeFlags[uDriveType]来代替线性查找。在实际的编程中通常可以这么做:
    // if (uDriveType & DEVICE_CDROM) {
             ……
    // }
          //
          for (int i=0; DriveTypeFlags[i].name; i++) {
             if (uDriveType == DriveTypeFlags[i].type) {
                msg += DriveTypeFlags[i].name;
                break;
             }
          }
          msg += ''''''''''''''''\n'''''''''''''''';
       }
       cout << msg.c_str();   return 0;
    }
      

  2.   

    检测光驱  drv指光驱在计算机上应该的盘符function TForm1.CDROMReady(DRV: char): boolean;
    vari:dword;buf:array[0..MAX_PATH] of char;pd:DWORD;beginpd:=0;GetVolumeInformation(pchar(DRV+':\'),buf,i,@pd,i,i,buf,i);result:=pd<>0;end;
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      if form1.CDROMReady('g')=true then
        showmessage('ready')
      else
        showmessage('no ready');
    end;
      

  3.   

    1,getlogicdrivers;
    The GetLogicalDrives function returns a bitmask representing the currently available disk drives. DWORD GetLogicalDrives(VOID)
     ParametersThis function has no parameters. Return ValuesIf 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. See AlsoGetLogicalDriveStrings
      

  4.   

    2,The GetDriveType function determines whether a disk drive is a removable, fixed, CD-ROM, RAM disk, or network drive. UINT GetDriveType(    LPCTSTR lpRootPathName  // address of root path 
       );
     ParameterslpRootPathNamePoints to a null-terminated string that specifies the root directory of the disk to return information about. If lpRootPathName is NULL, the function uses the root of the current directory.  Return ValuesThe return value specifies the type of drive. It can be one of the following values: Value Meaning
    0 The drive type cannot be determined.
    1 The root directory does not exist.
    DRIVE_REMOVABLE The drive can be removed from the drive.
    DRIVE_FIXED The disk cannot be removed from the drive.
    DRIVE_REMOTE The drive is a remote (network) drive.
    DRIVE_CDROM The drive is a CD-ROM drive.
    DRIVE_RAMDISK The drive is a RAM disk.
     See AlsoGetDiskFreeSpace
      

  5.   

    procedure TForm1.Button3Click(Sender: TObject);
    var
      i,j:integer;
      s:string;
      cdrom,ram:boolean;
      typ:integer;
    begin
      cdrom:=false;
      ram:=false;
      i:=form1.DriveComboBox1.Items.Count;
      if i>0 then
      begin
        for j:=0 to i-1 do
        begin
          s:=form1.DriveComboBox1.Items.Strings[j];
          typ:=getdrivetype(pchar(s));
          case typ of
          DRIVE_CDROM:cdrom:=true;
          DRIVE_RAMDISK:ram:=true;
          end;
        end;
      end;
      if cdrom=true then
        showmessage('装有光驱')
      else
        showmessage('没有装光驱');
      if ram=true then
        showmessage('装有软驱')
      else
        showmessage('没有装软驱');
    end;