|
-
Dec 1st, 2006, 01:37 PM
#1
Thread Starter
Lively Member
[RESOLVED] Selecting a Folder, Common Dialog control?
i want the user of my app to be able to select a folder that .txt files will be created in.
i'd like to use this using the windows common dialog control, or something similar. i dont want to save files, or open files, i want to just select a folder, so my app knows where to make the files
-
Dec 1st, 2006, 01:54 PM
#2
Re: Selecting a Folder, Common Dialog control?
Call the BrowseForFolder function like this:
VB Code:
BrowseForFolder Me.hWnd, "Select a folder to store the text files"
and the actual function
VB Code:
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
Private Const BIF_BROWSEFORCOMPUTER = &H1000
Private Const BIF_BROWSEFORPRINTER = &H2000
Private Const BIF_BROWSEINCLUDEFILES = &H4000
Private Const BIF_BROWSEINCLUDEURLS = &H80
Private Const BIF_DONTGOBELOWDOMAIN = &H2
Private Const BIF_EDITBOX = &H10
Private Const BIF_NEWDIALOGSTYLE = &H40
Private Const BIF_RETURNFSANCESTORS = &H8
Private Const BIF_RETURNONLYFSDIRS = &H1
Private Const BIF_SHAREABLE = &H8000
Private Const BIF_STATUSTEXT = &H4
Private Const BIF_USENEWUI = &H40
Private Const BIF_VALIDATE = &H20
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(ByVal hwnd As Long, Optional ByVal Title As String = "Select a folder") As String
'KPD-Team 1998
'URL: [url]http://www.allapi.net/[/url]
Dim iNull As Integer, lpIDList As Long, lResult As Long
Dim sPath As String, udtBI As BrowseInfo
With udtBI
.pszDisplayName = 0
.hWndOwner = hwnd 'Set the owner window
.lpszTitle = lstrcat(Title, "") 'lstrcat appends the two strings and returns the memory address
.ulFlags = BIF_RETURNONLYFSDIRS Or BIF_DONTGOBELOWDOMAIN Or BIF_NEWDIALOGSTYLE 'Return only if the user selected a directory
End With
lpIDList = SHBrowseForFolder(udtBI) 'Show the 'Browse for folder' dialog
If lpIDList Then
sPath = String$(MAX_PATH, 0)
SHGetPathFromIDList lpIDList, sPath 'Get the path from the IDList
CoTaskMemFree lpIDList 'free the block of memory
iNull = InStr(sPath, vbNullChar)
If iNull Then sPath = Left$(sPath, iNull - 1)
End If
BrowseForFolder = sPath
End Function
-
Feb 10th, 2007, 01:31 AM
#3
Lively Member
Re: [RESOLVED] Selecting a Folder, Common Dialog control?
Is there a way to set the initial folder w/ this code?
Also, can you restrict it to folders a user can write to, or do you have to check that once he/she chooses the folder?
-
Feb 10th, 2007, 02:24 AM
#4
Re: [RESOLVED] Selecting a Folder, Common Dialog control?
-
Feb 10th, 2007, 12:37 PM
#5
Lively Member
Re: [RESOLVED] Selecting a Folder, Common Dialog control?
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
|