zoukankan      html  css  js  c++  java
  • C++如何获得U盘的盘符以及U盘相关属性的代码

    下载: xok.la.app
    1. char diskPath[5] = { 0 };
    2.     DWORD allDisk = GetLogicalDrives(); //返回一个32位整数,将他转换成二进制后,表示磁盘,最低位为A盘
    3.  
    4.     if (allDisk!=0)
    5.     {
    6.         for (int i=0;i<11;i++)     //假定最多有10个磁盘
    7.         {
    8.             if ((allDisk & 1)==1)
    9.             {
    10.                 sprintf( diskPath, "%c", 'C'+i );
    11.                 strcat( diskPath, ":\\" );
    12.  
    13.                 if ( GetDriveType(diskPath)==DRIVE_REMOVABLE )
    14.                 {
    15.                     //AfxMessageBox( "检测到U盘", MB_OK );
    16.                     //AfxMessageBox( diskPath, MB_OK );
    17.  
    18.                     if( GetVolumeInformation(diskPath,0,0,0,0,0,0,0) ) //判断驱动是否准备就绪
    19.                     {
    20.                         AfxMessageBox( "U盘就绪", MB_OK );
    21.                         break;
    22.                                         }
    23.                 }
    24.             }
    25.  
    26.             allDisk = allDisk>>1;
    27.         }
    28.     }
    29.  
    30.     if ((allDisk & 1)!=1) //未检测到U盘
    31.     {
    32.         AfxMessageBox( "未检测到U盘,请插入U盘", MB_OK);
    33.     }
  • 相关阅读:
    Android之Handler实现延迟执行
    static{}语句块
    (转)git常见错误
    smarty使用
    git简易操作
    angular路由——ui.route
    angular服务二
    angular服务一
    angualr 实现tab选项卡功能
    EF 集合版 状态版的 增加、删除、修改 的实践
  • 原文地址:https://www.cnblogs.com/shihao/p/2324619.html
Copyright © 2011-2022 走看看