Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: Jeronimo17 en 3 Enero 2007, 05:37 am



Título: Crear carpeta usando SHBrowseForFolder
Publicado por: Jeronimo17 en 3 Enero 2007, 05:37 am
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  ;)

Código:
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


Título: Re: Crear carpeta usando SHBrowseForFolder
Publicado por: ~~ en 3 Enero 2007, 13:16 pm
Si, tienes q usar mkdir. Ej:

Código:
MkDir ("C:\zzz")

1S4ludo


Título: Re: Crear carpeta usando SHBrowseForFolder
Publicado por: CeLaYa en 3 Enero 2007, 14:42 pm
lo haces con la propiedad ulFlags

Código:
browse_info.ulFlags = BIF_USENEWUI Or BIF_RETURNONLYFSDIRS

también te dejo otras opciones que puesdes aplicar...
Código:
'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&


Título: Re: Crear carpeta usando SHBrowseForFolder
Publicado por: Jeronimo17 en 3 Enero 2007, 18:02 pm
Muchas Gracias a los 2 por responder, estoy contento lo he conseguio :)

No se nada de Api, pero me ha salido, asi Funciona:

Código:
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


Título: Re: Crear carpeta usando SHBrowseForFolder
Publicado por: CeLaYa en 3 Enero 2007, 18:55 pm
creo que te faltaría declarar la constante BIF_RETURNONLYFSDIRS y te sobra la linea "browse_info.ulFlags = 1 ' devuelve el nombre del directorio."


Título: Re: Crear carpeta usando SHBrowseForFolder
Publicado por: Jeronimo17 en 16 Marzo 2007, 17:10 pm
Hola depues de todo esto que funciona bien, tengo una ultima duda.

Este es el codigo que tengo:

Código:
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



Código:
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



Código:
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:

(http://img154.imageshack.us/img154/859/carpetatb1.png)

¿Alguna solucion?  :-(

Gracias de nuevo a todos  ;)