Results 1 to 4 of 4

Thread: [VB6] SHFolderDlg class: BrowseForFolder

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    [VB6] SHFolderDlg class: BrowseForFolder

    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 Attached Files

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,711

    Re: [VB6] SHFolderDlg class: BrowseForFolder

    What no custom filtering? Come on now

  3. #3
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,389

    Re: [VB6] SHFolderDlg class: BrowseForFolder

    If BIF_RETURNONLYFSDIRS is set I have made in my CommonDialog.cls a check with SHGetPathFromIDList to enable/disable the OK button.
    The reason is explained in the code below.

    This is done in response to BFFM_SELCHANGED
    Code:
    ' If the CdlBIFReturnOnlyFSDirs flag is set, the OK button remains enabled if the user selects a "\\ServerName" item.
    ' "\\ServerName" is not a file system path, but a machine name. Whereas "\\ServerName\ShareName\" is a file system path.
    ' Therefore it is necessary to check the return value of SHGetPathFromIDList and enable/disable the OK button accordingly.
    RetVal = SHGetPathFromIDList(lParam, StrPtr(Buffer))
    SendMessage hDlg, BFFM_ENABLEOK, 0, ByVal RetVal
    Last edited by Krool; Jan 19th, 2017 at 04:23 PM.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [VB6] SHFolderDlg class: BrowseForFolder

    Quote Originally Posted by Krool View Post
    If BIF_RETURNONLYFSDIRS is set I have made in my CommonDialog.cls a check with SHGetPathFromIDList to enable/disable the OK button.
    The reason is explained in the code below.

    This is done in response to BFFM_SELCHANGED
    Good point. I'll have to add that when I get back to this again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width