|
-
Apr 19th, 2002, 11:25 AM
#1
common dialog for directories only?
Any way I can get the common dialog box to understand that I want a directory instead of a file, or are there any other dialogs for that?
-
Apr 19th, 2002, 11:27 AM
#2
Someone posted this yesterday.. Works REALLY well!
VB Code:
Option Explicit
'This code was blagged off the internet, MSN site
'API declarations
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
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
'Constants
Private Const BIF_RETURNONLYFSDIRS = 1
Private Const BIF_DONTGOBELOWDOMAIN = 2
Private Const MAX_PATH = 260
'Types
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
Public Function funcBrowseFolder(WindowHandle As Long, BrowseTitle As String) As String
'Opens a Treeview control that displays the directories in a computer
Dim lpIDList As Long
Dim sBuffer As String
Dim szTitle As String
Dim tBrowseInfo As BrowseInfo
szTitle = BrowseTitle '"Select the folder to save to"
With tBrowseInfo
.hWndOwner = WindowHandle
.lpszTitle = lstrcat(szTitle, "")
.ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
End With
lpIDList = SHBrowseForFolder(tBrowseInfo)
If (lpIDList) Then
sBuffer = Space$(MAX_PATH)
SHGetPathFromIDList lpIDList, sBuffer
sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
funcBrowseFolder = sBuffer
End If
End Function
-
Apr 19th, 2002, 11:28 AM
#3
Fanatic Member
I belive you can do this though APIs. You could also just use the drive and the directory controls. I have also found (and made) controls which do both drives and directories. You can also fake it, by having the user select a file, then ignoring the selected file, and just use the folder (I have seen this in some professional programs).
-
Apr 19th, 2002, 11:30 AM
#4
Fanatic Member
As I said, it can be done though apis. By the way, I started writing the previous post before that was posted...
-
Apr 19th, 2002, 11:33 AM
#5
PowerPoster
might have to create your own form for that ...
or you could cheat:
VB Code:
Dim strarray() As String
cd1.ShowOpen
strarray = Split(cd1.FileName, "\")
ReDim Preserve strarray(UBound(strarray) - 1)
strFolder = Join(strarray, "\")
-
Apr 19th, 2002, 12:50 PM
#6
Thank you all for the replies
As usual there are more than one way to do things. I tested your suggestions and I will go with Joans suggestion. I figured it out at last, I'm a bit thickheaded sometimes.
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
|