判断驱动器的类型
使用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 来替换。
使用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 来替换。
解决方案 »
- 能否知道一个进程世纪使用的物理内存页面都有哪些?
- 怎么设置combobox的默认值
- 在次提问,Tab Control控件在页标签上显示位图,显示不出,但标签上有图象的位置,请高手指点谜睛
- 遇到问题了,请高手帮忙~~
- 浮点数比较
- Help Me,50 score
- vc+oracle+Ado时调用存储过程出现错误,不用savepoint时没问题,用了就出错怎么办。
- 我们现在用的显示器是什么类型的.如17寸纯平或17寸液晶的
- 江湖救急 鼠标消息的问题 好特别
- 怎么样设置一个对话框的背景色。
- 各位给推荐个免费空间,可以计算文件下载次数的那种
- 用DoModel()弹出一个模态对话框时,如何指定窗口出现的位置?
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
GetLogicalDriveStrings
就我的问题而言,用GetDriverType 和 GetLogicalDriveStrings 都能解决
问题,后者更简便一点!!
多谢 strip(阿飞) 和ccnuxjg(钢铁就是这样炼成的!) !
其他朋友也给予了提示,能从中学到东西!!