Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1449

[VB6] SHFolderDlg class: BrowseForFolder

$
0
0
A VB6 Class with one Method: BrowseForFolder()

It raises a Shell dialog for browsing to a folder. You can specify the "browse root" as well as an optional StartPath under that for the dialog to show selected.

Requirements

Some features require Windows 2000/Me or later, or Win9x with IE 5. Others require Windows XP or later. See comments for the Shell32.dll version requirements of some of the features.

It may be portable to Office VBA, though for 64-bit versions it could need tweaks to the data type of variables holding pointer values.


Features

The Class wraps a call to SHBrowseForFolder() in Shell32.dll, but with a callback supporting a number of other features via Properties you assign values to before calling the Method:

  • StartPath, a path below the browse root.
  • Root, the browse root directory. This accepts CSIDL values.
  • RootPath supports a String path as an alternative to Root.
  • Instructions can be used to set the dialog's "Title" text (this is not the dialog window's "title bar" caption).
  • ExpandStartPath instructs the dialog to open with the StartPath expanded (or not).
  • OkCaption allows you to specify the "Ok" button's caption text.


The Instructions property only displays as ANSI characters but everything else should be fully Unicode.


Advantages

The main advantage over a simple call is that your programs can start the user browsing from some given location under the root. For example where they last browsed to, or perhaps a value you store in a user settings file.

This can also be used to browse for files.


Demo Project

'This demo starts with an empty FolderPath, then loops until "cancel" reusing the most recently selected FolderPath. This just shows that your programs can start the user browsing from some given location, such as where they last browsed to.



There is nothing exotic here, it just makes use of a few more features than most VB6 examples. It isn't anything we haven't seen before in other sample code, but it adds a few features. I think all of the potential memory leaks have been resolved and it should be stable compared to most older samples.
Attached Files

Viewing all articles
Browse latest Browse all 1449

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>