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

[vb6] Unicode Browse For Folder

$
0
0
This is a unicode-compatible "Browse For Folder" dialog implementation. It offers options to customize the dialog beyond simple examples you may have seen. I have moved this to its own thread from the Unicode File Open/Save Dialog thread. It was becoming a bit confusing whether posts were talking about that solution or this solution.

Before I go too far into this, let me link an example from dilettante where CreateObject can be used. If you don't need any special customization, that is a fine solution and very simple to code.

The attached class has lots of methods/properties and nearly all of them are well-commented within the class. Therefore, not going to list them in this thread with few exceptions:

SelectedFolder contains a path/filename and/or PIDL of the item selected by the user.
InitialDirectory will attempt to select that as the folder first displayed/selected by the dialog
PathToPIDL is a convenience function to convert a path to a PIDL
PIDLtoPath is a convenience function to convert a PIDL to a path, if possible
ShowBrowseForFolder is the function that activates the dialog

BrowseForFolderMsgEnum lists common messages that can be sent to dialog via SendMessage
BrowseForFolderCallBackEnum lists common messages received in the dialog callback procedure
BrowseForFolderDialogFlagsEnum lists all the available flags the dialog may support (version limited)

Sample call might look like this:
Code:

Dim cb As UnicodeBrowseFolders
Set cb = New UnicodeBrowseFolders
With cb
    .DialogTitle = "Select Folder To Save Report"
    .Flags = BIF_RETURNONLYFSDIRS Or BIF_NEWDIALOGSTYLE
    .InitialDirectory = "C:\blah\blah\blah\Reports"
End With
If f.ShowBrowseForFolder(Me.hWnd) = True Then
    ' do what you need with the selection
    ' f.SelectedFolder() returns selected path if a non-virtual path selected
    ' f.SelectedFolder(True) returns a PIDL whether virtual path selected or not
End If

Here's an example of asking for events. The class can self-hook the dialog and send events that it receives to your form if you choose. There are three events that can be sent:
1) Initialized. The dialog's hWnd is provided. You are kinda unlimited to what you can do in this event.
2) SelectionChanged. Event sent whenever the dialog folder selection changes
3) CallBackMsg. Catch-all of other events forwarded from the dialog

Just one note. WantEvents property is ignored if you set the CustomHookProc property which means you are hooking the dialog and the class will not.
Code:

' you must declare the dialog using: WithEvents
Private WithEvents FolderBrowser As UnicodeBrowseFolders

' setup your dialog
Private Sub ShowBrowser()
    Set FolderBrowser = New UnicodeBrowseFolders
    With FolderBrowser
        .WantEvents = True
        ... set other properties
    End With
    If FolderBrowser.ShowBrowseForFolder(Me.hWnd) = True Then
        ' handle selected folder
    End If
End Sub


' respond/review events, i.e.,
Private Sub FolderBrowser_CallBackMsg(ByVal hWnd As Long, ByVal Message As Long, ByVal lParam As Long, ByVal UserParam As Long, CloseDialog As Boolean)

End Sub

Private Sub FolderBrowser_Initialized(ByVal hWnd As Long, ByVal UserParam As Long)

End Sub

Private Sub FolderBrowser_SelectionChanged(ByVal hWnd As Long, ByVal pPIDL As Long, ByVal UserParam As Long)

End Sub

Attached Files

Viewing all articles
Browse latest Browse all 1512

Trending Articles



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