|
-
Sep 29th, 2000, 11:35 PM
#1
Is it possible to use the standard commondialog control to get one of those dialog boxes that let you select a directory (kind of like MS SDK installatin EXEs where there is a tree view with all the directories)?
Sunny
-
Sep 29th, 2000, 11:39 PM
#2
You can use either the BrowseDialog control from CCRP (www.mvps.org/ccrp) or I'm pretty sure it can be done using the Shell TypeLib stuff (but I've never done it that way - the CCRP mehtod is easier)
- gaffa
-
Sep 29th, 2000, 11:44 PM
#3
-
Sep 29th, 2000, 11:56 PM
#4
This will display a dialog box allowing you to only select directories.
Code:
Option Explicit
Public 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
Public Const BIF_RETURNONLYFSDIRS = 1
Public Const MAX_PATH = 260
Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Public Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Public Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
Public 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
'declare variables to be used
Dim iNull As Integer
Dim lpIDList As Long
Dim lResult As Long
Dim sPath As String
Dim udtBI As BrowseInfo
'initialise variables
With udtBI
.hwndOwner = hwndOwner
.lpszTitle = lstrcat(sPrompt, "")
.ulFlags = BIF_RETURNONLYFSDIRS
End With
'Call the browse for folder API
lpIDList = SHBrowseForFolder(udtBI)
'get the resulting string path
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
'If cancel was pressed, sPath = ""
BrowseForFolder = sPath
End Function
Private Sub Command1_Click()
Dim strResFolder As String
strResFolder = BrowseForFolder(hWnd, "Please select a folder.")
If strResFolder = "" Then
Call MsgBox("The Cancel button was pressed.", vbExclamation)
Else
Call MsgBox("The folder " & strResFolder & " was selected.", vbExclamation)
End If
End Sub
-
Sep 30th, 2000, 12:13 AM
#5
and..is there a proper name for this type of box?
Sunny
-
Sep 30th, 2000, 12:18 AM
#6
A dialog box? Did I get it right? I'm sorry, I'm not very good with pop quizzes or tests .
What do you mean?
-
Sep 30th, 2000, 12:22 AM
#7
Well with the normal commondialog box theres save dialog box, open dialog box, printer dialog box and some others, whats this one called? choose-directory-only dialog box? 
Sunny
-
Sep 30th, 2000, 12:47 AM
#8
Browse Directory Dialog Box?
Folder Dialog Directory Box
Directory Dialog Box?
Folder Dialog Box?
BrowseFolder Dialog Box?
BrowseDirectory Dialog Box?
Browse For Folder Dialog Box?
Browse For Directory Dialog Box?
Is that the code you are going to use?
Choose a name, anyone is good.
Basically, you just tell it what you want to do.
strResFolder = BrowseForFolder(hWnd, "Please select a folder.")
All of what you need is there, just put it in a Command Button or whatever your using.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|