|
-
Feb 25th, 2006, 04:46 AM
#1
Thread Starter
Junior Member
[RESOLVED] common dialog
Is there a way to use the common dialog control just to get a folder's application path, I also need to create new folders in the dialog box.
Thanks in advance.
-
Feb 25th, 2006, 05:58 AM
#2
Re: common dialog
What's a folder's application path?
-
Feb 25th, 2006, 06:38 AM
#3
Thread Starter
Junior Member
Re: common dialog
Sorry I mean of course if I click on a folder I want to return the folders name, when you use commendialog you can create a new folder but you can only receive the name on a file not on a folder.
-
Feb 25th, 2006, 07:18 AM
#4
Re: common dialog
do you want to get the name and path of the "folder" you selected using commondialog or the name of the "file"??
Harsh Gupta
-
Feb 25th, 2006, 07:35 AM
#5
Thread Starter
Junior Member
Re: common dialog
I want to get the name and path of the "folder" I selected, but I also need to be able to create a new one from the dialog box.
-
Feb 25th, 2006, 08:18 AM
#6
Re: common dialog
using common dialog, it is too complicated because you cannot select a folder through it. but you can use it by selecting one file inside that folder:
VB Code:
Private Sub Command1_Click()
Dim iPath$
cd.ShowOpen
iPath = Mid$(cd.FileName, 1, InStrRev(cd.FileName, "\"))
'Path and Name of folder
MsgBox "Path of the folder is: " & iPath
MsgBox "Name of the folder is: " & Split(iPath, "\")(UBound(Split(iPath, "\")) - 1)
'Path and name of file
MsgBox "Path of the file is: " & cd.FileName
MsgBox "Name of the file is: " & cd.FileTitle
End Sub
common dialog has in-built "Create New Folder" Button next to "View Desktop" button.
Alternative method - recommended
use BrowseforFolder API, it will help you in selecting only folder, and return the path of the folder. (just a bit of coding and you may get the name of the folder yourself, not difficult):
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
Const BIF_RETURNONLYFSDIRS = 1
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
Private Sub Form_Load()
'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
'Set the owner window
.hWndOwner = Me.hWnd
'lstrcat appends the two strings and returns the memory address
.lpszTitle = lstrcat("C:\", "")
'Return only if the user selected a directory
.ulFlags = BIF_RETURNONLYFSDIRS
End With
'Show the 'Browse for folder' dialog
lpIDList = SHBrowseForFolder(udtBI)
If lpIDList Then
sPath = String$(MAX_PATH, 0)
'Get the path from the IDList
SHGetPathFromIDList lpIDList, sPath
'free the block of memory
CoTaskMemFree lpIDList
iNull = InStr(sPath, vbNullChar)
If iNull Then
sPath = Left$(sPath, iNull - 1)
End If
End If
MsgBox sPath
End Sub
to add a New folder, if you are using XP, then it would be not much problem. please take a look at this post.
you may notice that this also a new method of doing it.
of you are using Win 98, then it is very tricky, but take look at this thread.
hope it helps you.
Harsh Gupta
-
Feb 25th, 2006, 08:46 AM
#7
Thread Starter
Junior Member
Re: common dialog
Thank you, just what I look for.
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
|