List of drives

Hi I have created a combo box in my main window
 
 drives = CreateWindow(L"COMBOBOX", TEXT(""), CBS_DROPDOWN | CBS_HASSTRINGS | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE, 55, 50, 160, 30, hWnd, (HMENU)ID_COMBO, hInst, NULL);


combo box gets displayed successfully but How can I add the list of drives present in the computer I did this and my code complies with zero error and zero warning but I cannot see the strings added to my combo box

1
2
3
4
5
6
7
8
9
10
11
12
13

case WM_INITDIALOG:
		wchar_t szDrives[MAX_PATH];
		if (GetLogicalDriveStrings(MAX_PATH, szDrives))
		{
			wchar_t* pDrive = szDrives;
			while (*pDrive)
			{
				SendMessage(drives, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(pDrive));
				pDrive += wcslen(pDrive) + 1;
			}
		}


How can I add the drives present in the computer to the combo box present in my main window.

Thank you
Last edited on
Try this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
    case WM_INITDIALOG:
    {
      wchar_t szDrives[MAX_PATH];
      if (GetLogicalDriveStrings(MAX_PATH, szDrives))
      {
        wchar_t* pDrive = szDrives;
        while (*pDrive)
        {
          SendMessage(GetDlgItem(hwndDlg, ID_COMBO), CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(pDrive));
          pDrive += wcslen(pDrive) + 1;
        }
        SendMessage(GetDlgItem(hwndDlg, ID_COMBO), CB_SETCURSEL, (WPARAM)0, 0);
      }      
    }
It does displays only the C drive I mean the first drive present in the computer.
What should I do now?

I did used copied this
SendMessage(GetDlgItem(hwndDlg, ID_COMBO), CB_SETCURSEL, (WPARAM)0, 0);
and pasted inside the loop but still I see only C:\ drive

Thank you very much for all your help!
I did used copied this
SendMessage(GetDlgItem(hwndDlg, ID_COMBO), CB_SETCURSEL, (WPARAM)0, 0);and pasted inside the loop but still I see only C:\ drive


No normally you set the current selection only when it is completely populated.

Normally you should see the other drives when you click on the arrow and the combobox drops down. You need to increase the height of the combobox if you can't see all drives.
Yes, I did increased the the height of combo-box but I get something like this

C:\
D:\
E:\
F:\
C:\
D:\
E:\
F:\

I mean that the drives are repeated.
How to solve this?
Help me please

Thank you
I don't understand the problem.
I sent you a PM with a link to a demo app.
Topic archived. No new replies allowed.