Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Standard windows dialogue box for selecting a folder 2

Status
Not open for further replies.

Jonathan

Programmer
Mar 19, 1999
116
GB
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.<br>
<br>
Does anyone know if there is a Win API function or other easy method for achieving this (preferably without getting new ActiveX controls)<br>
<br>
Cheers<br>
<br>
Jonathan <br>

 
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.<br>
<br>

 
Hi,<br>
<br>
I have the following code snippet to which you are welcome. Provided with usual caveats 'use at peril' etc :&gt;.<br>
<br>
Put this in a module:<br>
<br>
Option Explicit<br>
<br>
Private Type BrowseInfo<br>
hWndOwner As Long<br>
pIDLRoot As Long<br>
pszDisplayName As Long<br>
lpszTitle As Long<br>
ulFlags As Long<br>
lpfnCallback As Long<br>
lParam As Long<br>
iImage As Long<br>
End Type<br>
<br>
'Browsing for directory.<br>
Private Const BIF_RETURNONLYFSDIRS = &H1 'For finding a folder to start document searching<br>
Private Const BIF_DONTGOBELOWDOMAIN = &H2 'For starting the Find Computer<br>
Private Const BIF_STATUSTEXT = &H4<br>
Private Const BIF_RETURNFSANCESTORS = &H8<br>
<br>
Private Const BIF_BROWSEFORCOMPUTER = &H1000 'Browsing for Computers.<br>
Private Const BIF_BROWSEFORPRINTER = &H2000 'Browsing for Printers<br>
Private Const BIF_BROWSEINCLUDEFILES = &H4000 'Browsing for Everything<br>
<br>
Private Const MAX_PATH = 260<br>
<br>
Private Declare Sub CoTaskMemFree Lib &quot;ole32.dll&quot; (ByVal hMem As Long)<br>
Private Declare Function lstrcat Lib &quot;kernel32&quot; Alias &quot;lstrcatA&quot; (ByVal _<br>
lpString1 As String, ByVal lpString2 As String) As Long<br>
<br>
Private Declare Function SHBrowseForFolder Lib &quot;shell32&quot; (lpbi As _<br>
BrowseInfo) As Long<br>
Private Declare Function SHGetPathFromIDList Lib &quot;shell32&quot; (ByVal pidList As _<br>
Long, ByVal lpBuffer As String) As Long<br>
<br>
Public Function BrowseForFolder(hWndOwner As Long, sPrompt As String) As String<br>
<br>
'=================================================<br>
'Opens the system dialog for browsing for a folder<br>
'=================================================<br>
Dim iNull As Integer<br>
Dim lpIDList As Long<br>
Dim lResult As Long<br>
Dim sPath As String<br>
Dim udtBI As BrowseInfo<br>
<br>
With udtBI<br>
.hWndOwner = hWndOwner<br>
.lpszTitle = lstrcat(sPrompt, &quot;&quot;)<br>
<br>
.ulFlags = BIF_RETURNONLYFSDIRS<br>
End With<br>
<br>
lpIDList = SHBrowseForFolder(udtBI)<br>
If lpIDList Then<br>
sPath = String$(MAX_PATH, 0)<br>
lResult = SHGetPathFromIDList(lpIDList, sPath)<br>
Call CoTaskMemFree(lpIDList)<br>
iNull = InStr(sPath, vbNullChar)<br>
If iNull Then<br>
sPath = Left$(sPath, iNull - 1)<br>
End If<br>
End If<br>
<br>
BrowseForFolder = sPath<br>
<br>
End Function<br>
<br>
<br>
<br>
<br>
Put this in a form:<br>
<br>
Private Sub Form_Click()<br>
Dim MyStr As String<br>
MyStr = BrowseForFolder(hWnd, &quot;Hello&quot;)<br>
MsgBox MyStr<br>
End Sub<br>
<br>
<br>
<br>
Click on the form, and see if it's what you want.....<br>
<br>
HTH<br>
<br>
Andrew<br>

 
Thanks, that is exactly what I was looking for.<br>
<br>
Jonathan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top