IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Access Discussion :

Selection de répertoire, avec répertoire racine [Sources]


Sujet :

Access

  1. #1
    Membre régulier
    Inscrit en
    Janvier 2005
    Messages
    104
    Détails du profil
    Informations forums :
    Inscription : Janvier 2005
    Messages : 104
    Points : 123
    Points
    123
    Par défaut Selection de répertoire, avec répertoire racine
    Bonjour,

    Je voudrais ouvrir une fenêtre qui permet à l'utilisateur de sélectionner un répertoire, avec un répertoire donné qui sera la racine. Pour cela j'ai trouvé ce code dans la FAQ :

    http://access.developpez.com/faq/?pa...Rep#select_rep

    Ca marche bien, mais je n'arrive pas à définir une racine. Je suppose qu'il faut passer par la propriété pIDLRoot, mais c'est un long. Comment je transforme le chemin de mon répertoire racine en pIDLRoot ?

    Merci d'avance pour vos conseils.

  2. #2
    Expert éminent
    Avatar de cafeine
    Inscrit en
    Juin 2002
    Messages
    3 904
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 3 904
    Points : 6 781
    Points
    6 781
    Par défaut
    Hello,

    tu trouveras ton bonheur par là >>> http://argyronet.developpez.com/offi...iaporama/#L3-2
    Ne mettez pas "Problème" dans vos titres, par définition derrière toute question se cache un problème
    12 tutoriels Access



  3. #3
    Expert éminent sénior

    Avatar de Tofalu
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Octobre 2004
    Messages
    9 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Associations - ONG

    Informations forums :
    Inscription : Octobre 2004
    Messages : 9 501
    Points : 32 311
    Points
    32 311
    Par défaut
    Bonjour,

    Pour obtenir l'IDList d'un répertoire, il faut utiliser SHGetIDListFromPath.



    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Private Declare Function SHGetIDListFromPath _
    Lib "SHELL32.DLL" Alias "#162" (ByVal szPath As String) As Long
    Attention le path doit être en unicode.


    Le paramètre pIDLRoot correspond à la racine de l'explorateur. Il sera impossible de choisir un répertoire parent dans ce cas.


    Ce qui donne :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    Public Function SelectFolder(Titre As String, Handle As Long, Racine As String) As String
     
    Dim lpIDList As Long
    Dim strBuffer As String
    Dim strTitre As String
    Dim tBrowseInfo As BrowseInfo
     
    strTitre = Titre
    With tBrowseInfo
        .pIDLRoot = SHGetIDListFromPath(StrConv(Racine, vbUnicode))
        .hWndOwner = Handle
        .lpszTitle = lstrcat(strTitre, "")
        .ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
    End With
     
    lpIDList = SHBrowseForFolder(tBrowseInfo)
     
    If (lpIDList) Then
        strBuffer = String(260, vbNullChar)
        SHGetPathFromIDList lpIDList, strBuffer
        SelectFolder = Left(strBuffer, InStr(strBuffer, vbNullChar) - 1)
    End If
     
    End Function
    En revanche, pour présélectionner un répertoire, c'est le paramètre lParam qui doit recevoir l'IDList. C'est plus compliqué car il faut faire appel à une fonction de rappel.

    Le module devient :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    Option Compare Database
     
    Private Const BIF_RETURNONLYFSDIRS = 1
    Private Const BIF_DONTGOBELOWDOMAIN = 2
    Private Const BFFM_INITIALIZED = 1
    Private Const WM_USER = &H400
    Private Const BFFM_SETSELECTIONA = (WM_USER + 102)
     
    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
    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
     
    Private Declare Function SHGetIDListFromPath Lib "SHELL32.DLL" Alias "#162" (ByVal szPath As String) As Long
     
    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
    Function adr(n As Long) As Long
    adr = n
    End Function
     
    Public Function BrowseCallbackProc(ByVal hWnd As Long, _
                                                          ByVal uMsg As Long, _
                                                          ByVal lParam As Long, _
                                                          ByVal lpData As Long) As Long
      If uMsg = BFFM_INITIALIZED Then
      'Quand la boite est ouverte actualise le chemin présélectionné
          Call SendMessage(hWnd, BFFM_SETSELECTIONA, False, ByVal lpData)
      End If
    End Function
     
     
     
    Public Function SelectFolder(Titre As String, Handle As Long, Racine As String) As String
     
    Dim lpIDList As Long
    Dim strBuffer As String
    Dim strTitre As String
    Dim tBrowseInfo As BrowseInfo
     
     
     
    strTitre = Titre
    With tBrowseInfo
        .hWndOwner = Handle
        .lpszTitle = lstrcat(strTitre, "")
        .ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
        .lpfnCallback = adr(AddressOf BrowseCallbackProc)
        .lParam = SHGetIDListFromPath(StrConv(Racine, vbUnicode))
    End With
     
    lpIDList = SHBrowseForFolder(tBrowseInfo)
     
    If (lpIDList) Then
        strBuffer = String(260, vbNullChar)
        SHGetPathFromIDList lpIDList, strBuffer
        SelectFolder = Left(strBuffer, InStr(strBuffer, vbNullChar) - 1)
    End If
     
    End Function
    Exemple :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Sub test()
    MsgBox SelectFolder("Hello", 0, "D:\essai")
    End Sub

  4. #4
    Expert éminent sénior

    Avatar de Tofalu
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Octobre 2004
    Messages
    9 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Associations - ONG

    Informations forums :
    Inscription : Octobre 2004
    Messages : 9 501
    Points : 32 311
    Points
    32 311
    Par défaut
    Citation Envoyé par cafeine
    Hello,

    tu trouveras ton bonheur par là >>> http://argyronet.developpez.com/offi...iaporama/#L3-2

    Avec cette solution et la mienne, on a vraiment un truc complet sur ce coup là

    Alllez hop, sources

  5. #5
    Membre régulier
    Inscrit en
    Janvier 2005
    Messages
    104
    Détails du profil
    Informations forums :
    Inscription : Janvier 2005
    Messages : 104
    Points : 123
    Points
    123
    Par défaut
    Nickel, merci

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Racine vs sous-répertoire avec .htaccess
    Par dancom5 dans le forum Apache
    Réponses: 8
    Dernier message: 11/02/2015, 00h17
  2. Lire un fichier avec répertoire avec des espaces
    Par boutss dans le forum Entrée/Sortie
    Réponses: 4
    Dernier message: 25/05/2007, 11h20
  3. Réponses: 11
    Dernier message: 25/04/2006, 09h33
  4. Réponses: 2
    Dernier message: 08/07/2005, 10h40
  5. Protection d'un répertoire avec .htaccess
    Par Bweb dans le forum Apache
    Réponses: 2
    Dernier message: 04/05/2004, 18h12

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo