|
-
Oct 9th, 2000, 02:33 PM
#1
Thread Starter
Lively Member
I have been using the common dialog control to allow users to browse and select a directory location. However using this requires that a file name also be provided. I have gotten by so far with this but I would rather just be able to allow users to select a directory location...period. Is there a variation of the common dialog control to do this or is there a way of getting common dialog to do it!!
-
Oct 9th, 2000, 03:32 PM
#2
Addicted Member
I have this code for the menu bar save. I hope this helps you out some.
Private Sub mnuFileSaveAs_Click()
On Local Error GoTo errhandler
CommonDialog1.CancelError = True )This allows the user to cancel the save)
CommonDialog1.Filter = "Text (*.txt)|*.txt|" (You can add other File Names here also)
CommonDialog1.Flags = cdlOFNOverwritePrompt (This gives the user the option to overwrite the data)
CommonDialog1.ShowSave
Open CommonDialog1.FileName For Output As #1
Print #1, Text1.Text
Close #1
errhandler:
Exit Sub
End Sub
Hope this helps you out!
jeffro
-
Oct 9th, 2000, 03:40 PM
#3
I think this is what you are looking for:
Code:
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
And after they select the folder, you can use CommonDialog's InitDir property to change it to that folder so that the folder is opened and the user can select a file in that folder.
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
|