Autor
|
Tema: Crear carpeta usando SHBrowseForFolder (Leído 5,238 veces)
|
Jeronimo17
Desconectado
Mensajes: 31
|
Hola, Tengo una preguntita sobre directorios, uso SHBrowseForFolder para mostrar un dialogo con los directorios, de donde cojo la ruta y guardo el archivo ahi, todo eso muy bien, pero queria añadirle un boton para crear nueva carpeta ¿Es posible? ¿Como seria? Gracias Private Type BrowseInfo hWndOwner As Long pidlRoot As Long sDisplayName As String sTitle As String ulFlags As Long lpfn As Long lParam As Long iImage As Long End Type
'Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private Declare Function SHBrowseForFolder Lib "Shell32.dll" (bBrowse As BrowseInfo) As Long Private Declare Function SHGetPathFromIDList Lib "Shell32.dll" (ByVal lItem As Long, ByVal sDir As String) As Long
Private Function BrowseForDirectory() As String Dim browse_info As BrowseInfo Dim item As Long Dim dir_name As String browse_info.hWndOwner = hwnd browse_info.pidlRoot = 0 browse_info.sDisplayName = Space$(260) browse_info.sTitle = "Selecionar una Carpeta" browse_info.ulFlags = 1 ' devuelve el nombre del directorio. browse_info.lpfn = 0 browse_info.lParam = 0 browse_info.iImage = 0 item = SHBrowseForFolder(browse_info) If item Then dir_name = Space$(260) If SHGetPathFromIDList(item, dir_name) Then BrowseForDirectory = Left(dir_name, _ InStr(dir_name, Chr$(0)) - 1) Else BrowseForDirectory = "" End If End If End Function
|
|
|
En línea
|
|
|
|
~~
|
Si, tienes q usar mkdir. Ej: 1S4ludo
|
|
|
En línea
|
|
|
|
CeLaYa
Desconectado
Mensajes: 543
|
lo haces con la propiedad ulFlags browse_info.ulFlags = BIF_USENEWUI Or BIF_RETURNONLYFSDIRS
también te dejo otras opciones que puesdes aplicar... 'For finding a folder to start document searching Private Const BIF_RETURNONLYFSDIRS As Long = &H1
'For starting the Find Computer Private Const BIF_DONTGOBELOWDOMAIN As Long = &H2
'Top of the dialog has 2 lines of text for 'BROWSEINFO.lpszTitle and one line if this flag is set. 'Passing the message BFFM_SETSTATUSTEXTA to the hwnd 'can set the rest of the text. This is not used with 'BIF_USENEWUI and BROWSEINFO.lpszTitle gets all three 'lines of text. Private Const BIF_STATUSTEXT As Long = &H4
Private Const BIF_RETURNFSANCESTORS As Long = &H8
'Add an editbox to the dialog: SHELL 5.0 or later only! Private Const BIF_EDITBOX As Long = &H10
'insist on valid result (or CANCEL) Private Const BIF_VALIDATE As Long = &H20
'Use the new dialog layout with the ability 'to resize: SHELL 5.0 or later only! Private Const BIF_NEWDIALOGSTYLE As Long = &H40 Private Const BIF_USENEWUI As Long = (BIF_NEWDIALOGSTYLE Or BIF_EDITBOX)
'Allow URLs to be displayed or entered '(Requires BIF_USENEWUI): SHELL 5.0 or later only! Private Const BIF_BROWSEINCLUDEURLS As Long = &H80
'Add a UA hint to the dialog, in place of the 'edit box. May not be combined with BIF_EDITBOX: SHELL 6.0 or later only! Private Const BIF_UAHINT As Long = &H100
'Do not add the "New Folder" button to the dialog. 'Only applicable with BIF_NEWDIALOGSTYLE: SHELL 5.0 or later only! Private Const BIF_NONEWFOLDERBUTTON As Long = &H200
'Browsing for Computers Private Const BIF_BROWSEFORCOMPUTER As Long = &H1000
'Browsing for Printers Private Const BIF_BROWSEFORPRINTER As Long = &H2000
'Browsing for Everything Private Const BIF_BROWSEINCLUDEFILES As Long = &H4000
'sharable resources displayed (remote shares, 'requires BIF_USENEWUI): SHELL 5.0 or later only! Private Const BIF_SHAREABLE As Long = &H8000&
|
|
|
En línea
|
"La soledad es el elemento de los grandes talentos". Cristina de Suecia (1626-1689) Reina de Suecia.
|
|
|
Jeronimo17
Desconectado
Mensajes: 31
|
Muchas Gracias a los 2 por responder, estoy contento lo he conseguio No se nada de Api, pero me ha salido, asi Funciona: Private Type BrowseInfo hWndOwner As Long pidlRoot As Long sDisplayName As String sTitle As String ulFlags As Long lpfn As Long lParam As Long iImage As Long End Type
'Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private Declare Function SHBrowseForFolder Lib "Shell32.dll" (bBrowse As BrowseInfo) As Long Private Declare Function SHGetPathFromIDList Lib "Shell32.dll" (ByVal lItem As Long, ByVal sDir As String) As Long 'Add an editbox to the dialog: SHELL 5.0 or later only! Private Const BIF_EDITBOX As Long = &H10
'insist on valid result (or CANCEL) Private Const BIF_NEWDIALOGSTYLE As Long = &H40 Private Const BIF_USENEWUI As Long = (BIF_NEWDIALOGSTYLE Or BIF_EDITBOX)
Private Function BrowseForDirectory() As String Dim browse_info As BrowseInfo Dim item As Long Dim dir_name As String browse_info.hWndOwner = hwnd browse_info.pidlRoot = 0 browse_info.sDisplayName = Space$(260) browse_info.sTitle = "Selecionar una Carpeta" browse_info.ulFlags = 1 ' devuelve el nombre del directorio. browse_info.lpfn = 0 browse_info.lParam = 0 browse_info.iImage = 0 browse_info.ulFlags = BIF_USENEWUI Or BIF_RETURNONLYFSDIRS item = SHBrowseForFolder(browse_info) If item Then dir_name = Space$(260) If SHGetPathFromIDList(item, dir_name) Then BrowseForDirectory = Left(dir_name, _ InStr(dir_name, Chr$(0)) - 1) Else BrowseForDirectory = "" End If End If End Function
Private Sub Command3_Click()
sRutaBrowserFolder = BrowseForDirectory
End Sub Gracias y Saludos
|
|
|
En línea
|
|
|
|
CeLaYa
Desconectado
Mensajes: 543
|
creo que te faltaría declarar la constante BIF_RETURNONLYFSDIRS y te sobra la linea "browse_info.ulFlags = 1 ' devuelve el nombre del directorio."
|
|
|
En línea
|
"La soledad es el elemento de los grandes talentos". Cristina de Suecia (1626-1689) Reina de Suecia.
|
|
|
Jeronimo17
Desconectado
Mensajes: 31
|
Hola depues de todo esto que funciona bien, tengo una ultima duda. Este es el codigo que tengo: Private Type BrowseInfo hWndOwner As Long pidlRoot As Long sDisplayName As String sTitle As String ulFlags As Long lpfn As Long lParam As Long iImage As Long End Type
'Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private Declare Function SHBrowseForFolder Lib "Shell32.dll" (bBrowse As BrowseInfo) As Long Private Declare Function SHGetPathFromIDList Lib "Shell32.dll" (ByVal lItem As Long, ByVal sDir As String) As Long 'Add an editbox to the dialog: SHELL 5.0 or later only! Private Const BIF_EDITBOX As Long = &H10
'insist on valid result (or CANCEL) Private Const BIF_NEWDIALOGSTYLE As Long = &H40 Private Const BIF_USENEWUI As Long = (BIF_NEWDIALOGSTYLE Or BIF_EDITBOX) Private Const BIF_RETURNONLYFSDIRS As Long = 1
Private Function BrowseForDirectory() As String Dim browse_info As BrowseInfo Dim item As Long Dim dir_name As String browse_info.hWndOwner = hWnd browse_info.pidlRoot = Carpeta browse_info.sDisplayName = Space$(260) browse_info.sTitle = "Selecionar una Carpeta" browse_info.lpfn = 0 browse_info.lParam = 0 browse_info.iImage = 0 browse_info.ulFlags = BIF_USENEWUI Or BIF_RETURNONLYFSDIRS item = SHBrowseForFolder(browse_info) If item Then dir_name = Space$(260) If SHGetPathFromIDList(item, dir_name) Then BrowseForDirectory = Left(dir_name, _ InStr(dir_name, Chr$(0)) - 1) Carpeta = item Else BrowseForDirectory = "" End If End If End Function
Private Sub Command3_Click() sRutaBrowserFolder = BrowseForDirectory Label8.Caption = sRutaBrowserFolder End Sub La variable Carpeta es la que guarda el numero referente a la ruta, y funciona bien, pero el problema es que depues me parte de ahi el arbol de directorios y no llega hasta Mi PC, o sea ,que no se puede llegar a la raiz, si no de la ruta guardada para delante Ejemplo: ¿Alguna solucion? Gracias de nuevo a todos
|
|
« Última modificación: 16 Marzo 2007, 17:20 pm por Jeronimo17 »
|
En línea
|
|
|
|
|
|