Browsing For Folders
Controllable Folder Browsing, including a method for creating a WinZip style Extract Dialog Box.
The Folder Browse Dialog is the missing dialog in VB - it can't be called from a run-time function and it is missing from the Common Dialog OCX as well. Whilst a number of code samples demonstrate that calling this dialog is simple, many ignore the most important feature: the ability to initialise the folder browse dialog to the user's previously selected folder or to some default.
This librbary also offers the ability to capture the Browse for Folder dialog into your own VB form and respond to browse events such as folder change.
About The Browse For Folder Dialog
The implementation of the Dialog is provided in vbalFlBr.DLL (VB5) or vbalFlBr6.DLL (VB6), which you will find under "vbAccelerator Folder Browse Library" in the references box once the object has been registered.
Two classes and one interface are exposed by the library. cBrowseForFolder is the class you will normally use to display a folder-browse dialog. cCaptureBF and iCaptureBF provide additional code wrappers allowing you to capture a folder browser into your own forms and further customise the appearance. These will be covered in turn.
This class exposes the standard Browse for folder dialog. You can either instantiate the class as you are about to use it, or you can create a WithEvents instance of it in order to respond to selection changes and validate the folder the user has chosen prior to closing the dialog.
To display the dialog, perform the following steps:
If you choose to create the class as a WithEvents instance then you can respond to the Initialized, SelectionChanged and ValidationFailed events.
Whilst the dialog is displayed, you can also change the status text using SetStatus and also modify the selected folder using SetFolder. Unless you are displaying the dialog non-modally, you will only be able to do this during one of the events.
Note that you don't have to use the DLL to take advantage of this code. If you would rather incorporate the code directly into your own project, just extract cBrowseForFolder.cls and mBrowseForFolder.bas from the download (the code in the VB5 and VB6 versions are both the same) and add them to your project.
cCaptureBF and iCaptureBF
These classes enable you to capture the folder browse dialog box into another VB form. This is a bit of a slimy hack I discovered whilst trying to create a customised file extract dialog similar to the one in WinZip, although it does appear stable and works fine on all systems MS have come up with so far.
The idea is basically to show the dialog modally and then capture it into a non-modal form, moving it to the correct location. The easiest way to build your own version of this code is to copy frmCapture from the sample project and then customise the UI.