Home Ask Login Register

Developers Planet

Your answer is one click away!

VISWESWARAN1998 February 2016

How to send these items in the combo box

I have created a combo box in my program. I have a function named add() which adds some files to the drive specified.

I searched Google on how to get the list of drives present in the computer, and found this:

DWORD var1 = 100;
WCHAR storeValue[100];
DWORD drives = GetLogicalDriveStrings(var1, storeValue);
for (int i = 0;i < 100;i++)
    return 0;

I want to add the drives present in the computer to the combo box, so that my function can add files to the specified drive. How can I do this? It is quiet tricky for a beginner.

I am very well aware this will be easier when we create something to browse the drive but I wish to do this in my combo box.


Jonathan Potter February 2016

GetLogicalDriveStrings fills your buffer with a double-null terminated array of strings. You can iterate through like this, stopping when the first character of the "next" string is null.

wchar_t szDrives[MAX_PATH];
if (GetLogicalDriveStrings(MAX_PATH, szDrives))
    wchar_t* pDrive = szDrives;
    while (*pDrive)
        // do something with pDrive

        // jump to next
        pDrive += wcslen(pDrive) + 1;

Now the "do something with pDrive" can in your case add the string to a combo box:

        SendMessage(hwndCombo, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(pDrive));

Post Status

Asked in February 2016
Viewed 3,247 times
Voted 5
Answered 1 times


Leave an answer

Quote of the day: live life