BrowseFolder dialog box

D

Dale Fye

I'm using the Browse Folder windows API to get the folder to save some files
in. What I was hoping I would find is an interface similar to the
FileOpenSave, which would allow me to add folders to the structure right in
the API.

Does anyone have a work-around for this? I'm actually using the version,
modified by Steve Lebans, that allows you to browse from a particular
location (path).

I guess I could build my own, but that would involve reading the file
structure into a treeview control, which tends to be time consuming. Would
appreciate any ideas.

--
HTH
Dale

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 
B

bhammer

Dale,

This one gives you the Make New Folder button on the bottom left.
I don't know which line it is, maybe one of the flags??

Put it in a Code Module. In your form put a textbox and a command button
with this on the Click event:

Text1 = GetFolder("Get Folder", Hwnd)


********Start Code Module text**********
Option Explicit

Type shellBrowseInfo
hwndOwner As Long
pidlRoot As Long
pszDisplayName As Long
lpszTitle As String
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
strInitDir As String
End Type

Const BIF_RETURNONLYFSDIRS = 1
Const BIF_NEWDIALOGSTYLE = 64
Const MAX_PATH = 400

Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Declare Function SHBrowseForFolder Lib "shell32" (lpbi As shellBrowseInfo)
As Long
Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, _
ByVal lpBuffer As String) As Long

Public Function GetFolder(dlgTitle As String, frmHwnd As Long) As String

Dim Nullchr As Integer
Dim IDList As Long
Dim Result As Long
Dim Folder As String
Dim BI As shellBrowseInfo

With BI
.hwndOwner = frmHwnd
.lpszTitle = dlgTitle
.strInitDir = "P:\"
.ulFlags = BIF_RETURNONLYFSDIRS + BIF_NEWDIALOGSTYLE
End With

IDList = SHBrowseForFolder(BI)
If IDList Then
Folder = String$(MAX_PATH, 0)
Result = SHGetPathFromIDList(IDList, Folder)
Call CoTaskMemFree(IDList) 'this frees the ole pointer to
IDlist
Nullchr = InStr(Folder, vbNullChar)
If Nullchr Then
Folder = Left$(Folder, Nullchr - 1)
End If
End If

GetFolder = Folder

End Functio
**********End Code*************
 
D

Dale Fye

What is the purpose of the "Hwnd" in the function call? How do I get that
value?

--
HTH
Dale

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 
D

Dale Fye

Thanks.

Disregard previous question, I figured it out.

The other problem with the call that I had was that I was unable to resize
the window. With this version, I was able to do that.
 
D

Dale Fye

I did notice, however, that although there is a parameter for strInitDir,
that this functionality does not appear to work.

--
HTH
Dale

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 
D

Dale Fye

Doug

That is what I'm currently using, but that code does not have the additions
for sizing the window or adding a new folder. The code that bhammer posted,
has this additional functionality, but without the initial directory.

I'm playing around with the two of them to get them to mesh and give me both
functionalities.
--
Dale

email address is invalid
Please reply to newsgroup only.
 
D

Douglas J. Steele

In my copy of Stephen's code, he doesn't seem to be setting ulFlags in the
BROWSEINFO structure in either BrowseForFolderByPath or
BrowseForFolderByPIDL. Add the line

ulFlags = BIF_RETURNONLYFSDIRS + BIF_NEWDIALOGSTYLE

and it should work.
 
B

bhammer

I agree. Don't forget you need to add:

Dim ulFlags As Long

Const BIF_RETURNONLYFSDIRS = 1
Const BIF_NEWDIALOGSTYLE = 64

and then
BI.ulFlags = BIF_RETURNONLYFSDIRS + BIF_NEWDIALOGSTYLE

where "Dim BI As BrowseInfo" in my example.

-Brad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top