un dialog box en VB pour choisir 1 dossier et pas un fichier

un dialog box en VB pour choisir 1 dossier et pas un fichier - VB/VBA/VBS - Programmation

Marsh Posté le 18-05-2003 à 18:05:17    

je voudrais un moyen de faire apparaitre unne dialog box comme "CommonDialog.showOpen" mais ki permet de selectionner un dossier et pas un fichier.
c important c pour un projet a rendre demain, help!
merci

Reply

Marsh Posté le 18-05-2003 à 18:05:17   

Reply

Marsh Posté le 19-05-2003 à 15:17:46    

si tu connais les API windows, tu peux le faire sans aucun problème. Si tu as des connaissances, dans les variables dynamique tu peux le faire aussi. RDv, sur www.vbfrance.com

Reply

Marsh Posté le 19-05-2003 à 16:40:45    

Exemple :

sPath = BrowseForFolder(Me, "Chemin d'archivage", txtArchiv.Text)


 
BrowseDirectorysOnly.bas


'=====================================================================================
' Browse for a Folder using SHBrowseForFolder API function with a callback
' function BrowseCallbackProc.
'
' This Extends the functionality that was given in the
' MSDN Knowledge Base article Q179497 "HOWTO: Select a Directory
' Without the Common Dialog Control".
'
' After reading the MSDN knowledge base article Q179378 "HOWTO: Browse for
' Folders from the Current Directory", I was able to figure out how to add
' a callback function that sets the starting directory and displays the
' currently selected path in the "Browse For Folder" dialog.
'
' I used VB 6.0 (SP3) to compile this code.  Should work in VB 5.0.
' However, because it uses the AddressOf operator this code will not
' work with versions below 5.0.
'
' This code works in Window 95a so I assume it will work with later versions.
'
' Stephen Fonnesbeck
' steev@xmission.com
' http://www.xmission.com/~steev
' Feb 20, 2000
'
'=====================================================================================
' Usage:
'
'    Dim folder As String
'    folder = BrowseForFolder(Me, "Select A Directory", "C:\startdir\anywhere" )
'    If Len(folder) = 0 Then Exit Sub  'User Selected Cancel
'
'=====================================================================================
 
Option Explicit
 
Private Const BIF_STATUSTEXT = &H4&
Private Const BIF_RETURNONLYFSDIRS = 1
Private Const BIF_DONTGOBELOWDOMAIN = 2
Private Const MAX_PATH = 260
 
Private Const WM_USER = &H400
Private Const BFFM_INITIALIZED = 1
Private Const BFFM_SELCHANGED = 2
Private Const BFFM_SETSTATUSTEXT = (WM_USER + 100)
Private Const BFFM_SETSELECTION = (WM_USER + 102)
 
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam 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 Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 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
 
Private m_CurrentDirectory As String   'The current directory
'
 
Public Function BrowseForFolder(owner As Form, Title As String, StartDir As String) As String
  'Opens a Treeview control that displays the directories in a computer
 
  Dim lpIDList As Long
  Dim szTitle As String
  Dim sBuffer As String
  Dim tBrowseInfo As BrowseInfo
  m_CurrentDirectory = StartDir & vbNullChar
 
  szTitle = Title
  With tBrowseInfo
    .hWndOwner = owner.hwnd
    .lpszTitle = lstrcat(szTitle, "" )
    .ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN + BIF_STATUSTEXT
    .lpfnCallback = GetAddressofFunction(AddressOf BrowseCallbackProc)  'get address of function.
  End With
 
  lpIDList = SHBrowseForFolder(tBrowseInfo)
  If (lpIDList) Then
    sBuffer = Space(MAX_PATH)
    SHGetPathFromIDList lpIDList, sBuffer
    sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
    BrowseForFolder = sBuffer
  Else
    BrowseForFolder = ""
  End If
   
End Function
 
Private Function BrowseCallbackProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal lp As Long, ByVal pData As Long) As Long
   
  Dim lpIDList As Long
  Dim ret As Long
  Dim sBuffer As String
   
  On Error Resume Next  'Sugested by MS to prevent an error from
                        'propagating back into the calling process.
     
  Select Case uMsg
   
    Case BFFM_INITIALIZED
      Call SendMessage(hwnd, BFFM_SETSELECTION, 1, m_CurrentDirectory)
       
    Case BFFM_SELCHANGED
      sBuffer = Space(MAX_PATH)
       
      ret = SHGetPathFromIDList(lp, sBuffer)
      If ret = 1 Then
        Call SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, sBuffer)
      End If
       
  End Select
   
  BrowseCallbackProc = 0
   
End Function
 
' This function allows you to assign a function pointer to a vaiable.
Private Function GetAddressofFunction(add As Long) As Long
  GetAddressofFunction = add
End Function


---------------
Des bons sites pour Delphi? http://forum.hardware.fr/forum2.php3?post=16838&cat=10 -- informaticien -- http://www.z0rglub.com/phpwebgallery/ -- Delphi :love:
Reply

Marsh Posté le 11-08-2007 à 13:37:15    

Bonjour,
 
J'ai vraiment besoin d'aide.Je dois réaliser un common dialog et je n'y arrive pas.j'ai essayé pleins de code,j'ai fais des modifs et je n'y arrive pas.Le code ci - dessus ne fonctionne pas sur XP. Est ce normale... merci d'avance.

Reply

Marsh Posté le 11-08-2007 à 16:13:33    

Reply

Marsh Posté le 11-08-2007 à 20:08:21    

Merci kiki,  
 
Mais le problème est que je réalise une application Web et que pour sauver un fichier, je dois permettre à l'utilisateur de choisir son dossier de sauvegarde.Dans l'exemple que vous m'avez passé, c'est utilisé pour Excel.  Quelqu'un aurait une solution svp???

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed