GetLogicalDrives()函数

原型:DWORD GetLogicalDrivers (void);

说明:函数返回值是一个long型,将其用二进制显示时,其中第0位表示A盘,第1位表示B盘,当某位为1时说明存在这个盘,即00000011表示有A盘和B盘。

看这个例子:

#include <windows.h>
int main()
{
DWORD dw;
TCHAR TC1[50],TC2[50];


dw = GetLogicalDrives();
wsprintf(TC1,"%ld",dw);
MessageBox(NULL,TC1,"十进制",MB_OK);


_itoa(dw,TC2,2);
MessageBox(NULL,TC2,"十进制",MB_OK);
return 0;
}

  一目了然哈


改下:

#include <windows.h>
int main()
{
DWORD dw;
TCHAR TC[50];
    int count = 0;
dw = GetLogicalDrives();
while(dw != 0)
{
   if( (dw&1) != 0)
   {
       count++;
   }
   dw >>= 1;
}
wsprintf(TC,"驱动器个数:%d",count);
MessageBox(NULL,TC,"我插了U盘的",MB_OK);
return 0;
}


判断某个盘符是否存在:

#include <windows.h>
int main()
{
    DWORD dw;
    TCHAR TC[50];
    dw = GetLogicalDrives();
    char ch;
    ch = 'Q';
    int n = ch - 'A';


    if( (dw != 0) && (dw >>= n) != 0 )
    {
        wsprintf(TC,"%c 盘 存 在",ch);
    }
    else
    {
        wsprintf(TC,"%c 盘 不 存 在",ch);
    }


    MessageBox(NULL,TC,"判断 该盘 是否存在",MB_OK);
    return 0;
}





MSDN:

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.

Remarks

Windows XP: This function returns a concatenation of the logical disks in the Global and Local MS-DOS Device namespaces. If a logical disk exists in both namespaces, this function will return the entry in the Local MS-DOS Devices namespace.

For more information on the Global and Local MS-DOS Device namespaces and changes to the accessibility of MS-DOS device names in Windows XP, refer to MS-DOS Device Names.

Requirements

Windows NT/2000/XP: Included in Windows NT 3.1 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.




  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值