GetLogicalDrives()用于循环 [英] GetLogicalDrives() for loop

查看:126
本文介绍了GetLogicalDrives()用于循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Win32 API的新手,需要帮助来尝试了解GetLogicalDrives()函数的工作方式。我正在尝试使用所有未使用的可用驱动器填充cbs_dropdownlist。这是我到目前为止所拥有的。我将不胜感激。

I am new to the win32 api and need help trying to understand how the GetLogicalDrives() function works. I am trying to populate a cbs_dropdownlist with all the available drives that are not in use. here is what I have so far. I would appreciate any help.

void FillListBox(HWND hWndDropMenu)
{
 DWORD drives = GetLogicalDrives();
 for (int i=0; i<26; i++)
 {
    SendMessage(hWndDropMenu, CB_ADDSTRING, 0, (LPARAM)drives);
 }
}


推荐答案

函数 GetLogicalDrives 返回可用逻辑驱动器的位掩码。这是您的操作方法:

The function GetLogicalDrives returns a bitmask of the logical drives available. Here is how you would do it:

 DWORD drives = GetLogicalDrives();
 for (int i=0; i<26; i++)
 {
    if( !( drives & ( 1 << i ) ) )
    {
       TCHAR driveName[] = { TEXT('A') + i, TEXT(':'), TEXT('\\'), TEXT('\0') };
       SendMessage(hWndDropMenu, CB_ADDSTRING, 0, (LPARAM)driveName);
    }
 }

代码检查是否 i-th bitmask 中的位未设置为 1 true code>。

The code checks whether the i-th bit in the bitmask is not set to 1 or true.

这篇关于GetLogicalDrives()用于循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆