Visualizzazione dei risultati da 1 a 7 su 7
  1. #1
    Utente di HTML.it
    Registrato dal
    Mar 2002
    Messaggi
    7

    [VB6] Root di partenza per SHBrowseForFolder

    Ciao,

    vorrei aprire la dialog box richiamabile con la funzione SHBrowseForFolder
    impostando come root una specifica cartella del disco.
    Ho visto che la struttura BROWSEINFO contiene un parametro che mi
    permette di impostare tale valore (pidlRoot).
    Supponiamo che io voglia aprire la dialog box con root su: C:\HTML.IT
    Per ora l'unica soluzione che ho trovato è stata: :quote: :quote:
    - Aprire la dialog box di SHBrowseForFolder con root standard (0 - Desktop)
    - Selezionare la cartella "C:\HTML.IT"
    - Prendere il valore restituito dalla SHBrowseForFolder ed impostare a mano
    tale valore nel parametro .pidlRoot per tutte le successive chiamate.

    Così funziona, però questo metodo non mi piace proprio.
    Come posso fare a recuperare il valore di CSIDL per la mia folder?
    Più in generale, come posso recuperare tale valore avendo il path di una
    qualsiasi folder?

    Ringrazio davvero tutti quelli che potranno essermi di aiuto... è urgente!
    Infatti è domenica ma ci sto lavorando....

    P.S.: Includo il codice...

    codice:
    Public Function Browse(BIF_FLAGS As Long, sTitle As String, hwindow) As String
        
        'Dichiarazione di variabili
        Dim pidl As Long
        Dim BI As BROWSEINFO
        Dim sPath As String
        Dim pos As Integer
        
        'Riempie la struttura BROWSEINFO (CommonModule).
        With BI
            .hOwner = hwindow
            
            'Mettendo a mano 1923696 si apre con la root giusta.
            '1923696 valore restituito dalla SHBrowseForFolder sulla folder c:\HTML.IT
            '.pidlRoot = CSIDL	
            .pidlRoot = 1923696
            
            .lpszTitle = "Browse " & sTitle
            .ulFlags = BIF_FLAGS
            .pszDisplayName = Space$(MAX_PATH)
        End With
        
        'Visualizza la finestra di dialogo.
        pidl = SHBrowseForFolder(BI)
        ...

  2. #2
    non ho capito dove stà il problema...???

    PS...quello è tutto il codice per far apparire la finestra di dialogo o solo una parte??
    Let's your dream came true!

  3. #3
    Utente di HTML.it
    Registrato dal
    Mar 2002
    Messaggi
    7
    Quello è una parte del codice, comunque sufficiente per mostrare
    la finestra.
    Il problema è che io vorrei permettere la navigazione solo all'interno di una certa cartella, appunto per esempio C:\HTML.IT
    Non voglio che l'utente possa selezionare cartelle che stanno al di fuori di questo sotto albero.

    Ho trovato in questo forum una funzione che, dato in input la stringa contenente il percorso della cartella, dovrebbe restituire il CSIDL associato.

    codice:
    Private Declare Function SHSimpleIDListFromPath Lib "shell32" Alias "#162" (ByVal szPath As String) As Long
    
    ...
    Dim lroot As Long
    rPath = "C:\HTML.IT"
    lroot = SHSimpleIDListFromPath(rPath)
    ...però mi restituisce sempre 0!!!!!!

    Sbaglio qualche cosa? Dimentico qualcosa?
    Grazie!!!!

  4. #4
    tieni...questo è un elenco più completo della funzione BrowseForFolder...con tutti i possibili parametri da passare...etc

    codice:
    [supersaibal]
    Option Explicit
    
    ' Maximum long filename path length
    Private Const MAX_PATH = 1024
    
    'SendMessage Constants
    Private Const BFFM_INITIALIZED = 1
    Private Const WM_USER = &H400
    Private Const BFFM_SETSELECTIONA = (WM_USER + 102)
    
    'The Following Constants may be passed to BrowseForFolder
    'as vTopFolder or vSelPath
    Public Const CSIDL_DESKTOP = &H0    'DeskTop
    Public Const CSIDL_PROGRAMS = &H2   'Program Groups Folder
    Public Const CSIDL_CONTROLS = &H3   'Control Panel Icons Folder
    Public Const CSIDL_PRINTERS = &H4   'Printers Folder
    Public Const CSIDL_PERSONAL = &H5   'Documents Folder
    Public Const CSIDL_FAVORITES = &H6  'Favorites Folder
    Public Const CSIDL_STARTUP = &H7    'Startup Folder
    Public Const CSIDL_RECENT = &H8     'Recent folder
    Public Const CSIDL_SENDTO = &H9     'SendTo Folder
    Public Const CSIDL_BITBUCKET = &HA  'Recycle Bin Folder
    Public Const CSIDL_STARTMENU = &HB  'Start Menu Folder
    Public Const CSIDL_DESKTOPDIRECTORY = &H10  'Windows\Desktop Folder
    Public Const CSIDL_DRIVES = &H11    'Devices Virtual Folder (My Computer)
    Public Const CSIDL_NETWORK = &H12   'Network Neighborhood Virtual Folder
    Public Const CSIDL_NETHOOD = &H13   'Network Neighborhood Folder
    Public Const CSIDL_FONTS = &H14     'Fonts Folder
    Public Const CSIDL_TEMPLATES = &H15 'ShellNew folder
    
    Private Type SHItemID
        cb      As Long    'Size of the ID (including cb itself)
        abID    As Byte    'The item ID (variable length)
    End Type
    
    Private Type ItemIDList
        mkid    As SHItemID
    End Type
    
    Private Type BROWSEINFO
        hOwner          As Long
        pidlRoot        As Long
        pszDisplayName  As String
        lpszTitle       As String
        ulFlags         As Long
        lpCallbackProc  As Long
        lParam          As Long
        iImage          As Long
    End Type
    
    Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
    Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
    'Retrieves the location of a special (system) folder.
    Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ItemIDList) As Long
    'ParseDisplayName function should be used instead of this undocumented function.
    Private Declare Function SHSimpleIDListFromPath Lib "shell32" Alias "#162" (ByVal szPath As String) As Long
    Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    Public Function BrowseCallbackProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal lParam As Long, ByVal lpData As Long) As Long
        
        Select Case uMsg
            Case BFFM_INITIALIZED
                ' Set the dialog's pre-selected folder using the pidl
                ' set in bi.lParam and passed in the lpData param.
                Call SendMessage(hWnd, BFFM_SETSELECTIONA, False, ByVal lpData)
        
        End Select
    
    End Function
    
    Public Function BrowseForFolder(hOwnerWnd As Long, Optional ByVal sInstruct As String, Optional vSelPath As Variant, Optional vTopFolder As Variant) As String
    
    ' Shows the Browse For Folder dialog
    '
    ' hOwnerWnd     (Long)                     OwnerWindow.hWnd.
    ' sInstruct     (String)                   Instructions for user.
    ' vSelPath      (String or CSIDL Constant) Pre-select this Folder.
    ' vTopFolder    (String or CSIDL Constant) Set the Top folder.
    '
    ' If successful, returns the selected folder's full path,
    ' returns an empty string otherwise.
    '
    
    Dim lRet As Long
    Dim pidlRet As Long
    Dim sPath As String * MAX_PATH
    Dim lItemIDList As ItemIDList
    Dim uBrowseInfo As BROWSEINFO
        
        With uBrowseInfo
            ' The desktop will own the dialog
            .hOwner = hOwnerWnd
            ' dialog root folder
            ' se è omesso il parametro
            If IsMissing(vTopFolder) Then
                'imposta vtopfolder come la costante definita
                vTopFolder = CSIDL_DESKTOP
            End If
            If Len(vTopFolder) > 0 And Not IsNumeric(vTopFolder) Then
                'String Path passed in
                .pidlRoot = SHSimpleIDListFromPath(CStr(vTopFolder))
            Else
                'Long CSIDL Special Folder Constant or Nothing passed in.
                lRet = SHGetSpecialFolderLocation(ByVal hOwnerWnd, ByVal CLng(vTopFolder), lItemIDList)
                .pidlRoot = lItemIDList.mkid.cb
            End If
            ' Set the dialog's prompt string
            .lpszTitle = sInstruct
            ' Obtain and set the address of the callback function
            .lpCallbackProc = FarProc(AddressOf BrowseCallbackProc)
            ' Obtain and set the pidl of the pre-selected folder
            If IsMissing(vSelPath) Then
                'Nothing passed in
                .lParam = .pidlRoot
            ElseIf Len(vSelPath) > 0 And Not IsNumeric(vSelPath) Then
                'String Path passed in
                .lParam = SHSimpleIDListFromPath(CStr(vSelPath))
            Else
                'Long CSIDL Special Folder Constant passed in
                lRet = SHGetSpecialFolderLocation(ByVal hOwnerWnd, ByVal CLng(vSelPath), lItemIDList)
                .lParam = lItemIDList.mkid.cb
            End If
        End With
        
        ' Shows the browse dialog and doesn't return until the dialog is
        ' closed. The BrowseCallbackProc will receive all browse
        ' dialog specific messages while the dialog is open. pidlRet will
        ' contain the pidl of the selected folder if the dialog is not cancelled.
        pidlRet = SHBrowseForFolder(uBrowseInfo)
        
        If pidlRet > 0 Then
            ' Get the path from the selected folder's pidl returned
            ' from the SHBrowseForFolder call (rtns True on success,
            ' sPath must be pre-allocated!)
            If SHGetPathFromIDList(pidlRet, sPath) Then
              ' Return the path
              BrowseForFolder = Left$(sPath, InStr(sPath, vbNullChar) - 1)
            End If
            ' Free the memory the shell allocated for the pidl.
            Call CoTaskMemFree(pidlRet)
        End If
        
        ' Free the memory the shell allocated for the pre-selected folder.
        Call CoTaskMemFree(uBrowseInfo.lParam)
      
    End Function
    
    Public Function FarProc(lpProcName As Long) As Long
    
    'Returns the value of the AddressOf operator
        
        FarProc = lpProcName
    
    End Function
    
    [/supersaibal]
    come puoi ben notare in questo caso la funzione BrowseForFolder ti restituisce ad esempio c:\html.it mentre la funzione SHBrowseForFolder ti restituisce il CSIDL della cartella...è inoltre possibile passare questo valore alla funzione BrowseForFolder
    Let's your dream came true!

  5. #5
    Utente di HTML.it
    Registrato dal
    Mar 2002
    Messaggi
    7
    Grazie 1000!!!

    Ci provo e ti faccio sapere!!!!!

  6. #6
    Utente di HTML.it
    Registrato dal
    Mar 2002
    Messaggi
    7
    Ciao ale500,
    ho provato ad usare il codice che hai postato.

    Anch'io ho usato la funzione SHSimpleIDListFromPath per recuperare l'ID di un folder partendo dal suo percorso del folder.
    Ma chiamando:
    codice:
    .pidlRoot = SHSimpleIDListFromPath("C:\HTML")
    io ottenevo sempre 0!!!! La dialogo box si continuava ad aprire sempre con root il desktop!


    Purtroppo usando il codice che hai postato ottengo lo stesso risultato ma, ho scoperto che...
    ...
    su Windows XP non funziona.

    Ho infatti provato su WIN98 (che poi è il sistema dove dovrà girare il programma) e funziona tutto perfettamente.

    Io però sto sviluppando il programma con VB6 e WindowsXP.

    C'è qualcuno che ha riscontrato lo stesso problema? ...e ha trovato una soluziona alternativa???

    Ciao!

  7. #7
    ora provo con il 2000...potrebbe darsi che in alcuni sistemi operativi è cambiata la finestra di sfoglia cartella...
    Let's your dream came true!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.