- Organize Downloads with HandsDown
- HandsDown: Download It Here
HandsDown lets the user select a default download directory for files that are pasted into the file-download list. The common Windows dialogs for opening and saving files, wrapped by the MFC class CFileDialog, are no help when you need to select a directory. In earlier versions of Windows, I would have had to create a directory-selection dialog from scratch or perform major surgery on one of the common dialogs. However, the modern Windows shell used by Windows 95 and Windows NT 4 includes the powerful function SHBrowseForFolder(), which is designed specifically for the task of letting the user choose a directory.
SHBrowseForFolder() takes as its only parameter a BrowseInfo structure that, among other things, defines what types of folders should be displayed and where the folder tree should be rooted. HandsDown needs a tree that displays only file-system folders, so it sets the ulFlags member of the BrowseInfo structure to BIF_RETURNFSANCESTORS|BIF_ RETURNONLYFSDIRS. The tree should show all possible download locations, including nonmapped network drives. To achieve this, HandsDown simply passes NULL as the BrowseInfo structure's pIdlRoot member. The value returned by SHBrowseForFolder() is a PITEMIDLIST rather than a text string, but a call to SHGetPathFromIDList() converts it to a more useful form. Finally, before exiting, HandsDown must free the memory allocated for the PITEMIDLIST using the shell's own pMalloc object. Keep SHBrowseForFolder in mind anytime your program needs to prompt for a folder.