A Drop-Down-Listbox for Drives

WEBINAR: On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >

For an installation application, I needed a control to have the user choose the target installation drive. Since the application is targeted for Windows 95/98/NT, I thought it would be nice to use at least the same names as the Windows Explorer. When I found out where to get them (SHGetFileInfo) I saw that this function would also return the respective icons. Why not use both in that control? This was when I looked at the Codeguru's pages.

I found no code ready to copy but with the help of other contributors (special thanks to Mark Otway on his information on the system image list) it was not too difficult to figure out the rest by myself.

Please regard this control as a hint on "how to" - not as a full-blown control class. The information should provide you with a grip on how to use CComboBoxEx with display names and icons from the Windows shell.

CDrvListBox is a drop down list box which shows all drives on the local computer with the same icons and names as the explorer. The control is derived from CComboBoxEx. Use it instead of a CComboBoxEx and invoke LoadItems() in the OnInitDialog() of the parent dialog. By default, small icons are displayed but you may specify ( true ) as parameter to LoadItems() to request the large icons. This will also increase the size of your edit box (automatically)! GetDataPtr() will retrieve a pointer a string containing the root path (e.g. for "Harddisk1 (C:)" this would be "C:\").

The implementation proved to be quite straight forward:

  • GetLogicalDriveStrings would give me the root paths for all drives known in the system. In my application, this comes in handy when I need the result of the user's choice.
  • SHGetFileInfo - when given the right paramters - gives me the display names and an index into the system image list.
  • Using CComboBoxEx.InsertItem() was used to load the list - it appears to be quite similar to filling a CListView control. Important: the index for both the standard image and the selected image must be provided, otherwise the icon for a selected item will not show in either the list box or the edit field (CBEItem.mask = CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | ... and CBEItem.iSelectedImage = CBEItem.iImage = FileInfo.iIcon; ).
  • Finally, the system image list needs to attached to the control.

The demo was generated with VC6.0a on NT4.0. When you compile and test, use the debug mode - I use the TRACE macros to do track error conditions and report intermediate results.

Download demo project - 12 KB

Download source - 3 KB



Comments

  • A Drop-Down-Listbox for Drives

    Posted by Legacy on 09/24/2002 12:00am

    Originally posted by: Matt Nilsen

    This is a nice control, but is there any way to auto scroll through the items by typing on the keyboard? It seems that when you go from CComboBox to CComboBoxEx, that this functionality is lost. At least, I can't seem to find any CComboBoxEx where this is supported.

    Is there a way to have an image associated with an item in a combo box, and have the text still auto-scroll?

    Reply
  • Adding large number of records in sorted combobox

    Posted by Legacy on 06/21/2002 12:00am

    Originally posted by: Puneet Jain

    I am finding difficult in initializing the combobox with large number of records and then sorting it.
    Every time, a function is called, its takes a long time to read the records and sort them.
    Is there any way, where after the first use, the process takes a very short time after every reuse.
    I am using VC++ as my application.

    Thanks
    -Puneet

    Reply
  • You have to modify the .rc file

    Posted by Legacy on 04/24/2002 12:00am

    Originally posted by: LB

    For people that this doesn't work, make sure your .rc file describes the combobox as follows:
    
    

    CONTROL "",IDC_COMBO1,"ComboBoxEx32",
    CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL |
    WS_TABSTOP,113,39,77,60

    and not as

    COMBOBOX IDC_COMBO1, 113,39,77,60,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP

    Reply
  • A Drop-Down-Listbox for Drives

    Posted by Legacy on 10/12/1999 12:00am

    Originally posted by: Re

    Not working in win 98

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date