×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Standard windows dialogue box for selecting a folder
2

Standard windows dialogue box for selecting a folder

Standard windows dialogue box for selecting a folder

(OP)
I am using the Windows API in my application to allow the user to easily select files to open using the standard windows Open File box. I also need to provide some means of selecting a folder. An example of what I want can be seen by going to the start menu, clicking Find - Files or Folders and clicking the Browse... button next to the Look In combo.

Does anyone know if there is a Win API function or other easy method for achieving this (preferably without getting new ActiveX controls)

Cheers

Jonathan

RE: Standard windows dialogue box for selecting a folder

I AM TRYING TO CREATE A VB6 PROGRAM TO ALLOW THE USERS TO SELECT A FILE AND COPY FILE FROM ONE DRIVE TO ANOTHER. PLEASE HELP.

RE: Standard windows dialogue box for selecting a folder

2
Hi,

I have the following code snippet to which you are welcome. Provided with usual caveats 'use at peril' etc :>.

Put this in a module:

Option Explicit

Private Type BrowseInfo
hWndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type

'Browsing for directory.
Private Const BIF_RETURNONLYFSDIRS = &H1 'For finding a folder to start document searching
Private Const BIF_DONTGOBELOWDOMAIN = &H2 'For starting the Find Computer
Private Const BIF_STATUSTEXT = &H4
Private Const BIF_RETURNFSANCESTORS = &H8

Private Const BIF_BROWSEFORCOMPUTER = &H1000 'Browsing for Computers.
Private Const BIF_BROWSEFORPRINTER = &H2000 'Browsing for Printers
Private Const BIF_BROWSEINCLUDEFILES = &H4000 'Browsing for Everything

Private Const MAX_PATH = 260

Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal _
lpString1 As String, ByVal lpString2 As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As _
BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As _
Long, ByVal lpBuffer As String) As Long

Public Function BrowseForFolder(hWndOwner As Long, sPrompt As String) As String

'=================================================
'Opens the system dialog for browsing for a folder
'=================================================
Dim iNull As Integer
Dim lpIDList As Long
Dim lResult As Long
Dim sPath As String
Dim udtBI As BrowseInfo

With udtBI
.hWndOwner = hWndOwner
.lpszTitle = lstrcat(sPrompt, "")

.ulFlags = BIF_RETURNONLYFSDIRS
End With

lpIDList = SHBrowseForFolder(udtBI)
If lpIDList Then
sPath = String$(MAX_PATH, 0)
lResult = SHGetPathFromIDList(lpIDList, sPath)
Call CoTaskMemFree(lpIDList)
iNull = InStr(sPath, vbNullChar)
If iNull Then
sPath = Left$(sPath, iNull - 1)
End If
End If

BrowseForFolder = sPath

End Function




Put this in a form:

Private Sub Form_Click()
Dim MyStr As String
MyStr = BrowseForFolder(hWnd, "Hello")
MsgBox MyStr
End Sub



Click on the form, and see if it's what you want.....

HTH

Andrew

RE: Standard windows dialogue box for selecting a folder

(OP)
Thanks, that is exactly what I was looking for.

Jonathan

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close