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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
Public Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Enum esFlags
OFN_ALLOWMULTISELECT = &H200
OFN_CREATEPROMPT = &H2000
OFN_ENABLEHOOK = &H20
OFN_ENABLETEMPLATE = &H40
OFN_ENABLETEMPLATEHANDLE = &H80
OFN_EXPLORER = &H80000
OFN_EXTENSIONDIFFERENT = &H400
OFN_FILEMUSTEXIST = &H1000
OFN_HIDEREADONLY = &H4
OFN_LONGNAMES = &H200000
OFN_NOCHANGEDIR = &H8
OFN_NODEREFERENCELINKS = &H100000
OFN_NOLONGNAMES = &H40000
OFN_NONETWORKBUTTON = &H20000
OFN_NOREADONLYRETURN = &H8000
OFN_NOTESTFILECREATE = &H10000
OFN_NOVALIDATE = &H100
OFN_OVERWRITEPROMPT = &H2
OFN_PATHMUSTEXIST = &H800
OFN_READONLY = &H1
OFN_SHAREAWARE = &H4000
OFN_SHOWHELP = &H10
End Enum
Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Public Function FichierOuvrir(I_lngHwnd As Long, _
I_strFiltre As String, _
I_lngIdxFiltre As Long, _
Optional I_lngFlags As esFlags = OFN_HIDEREADONLY + OFN_EXPLORER + OFN_LONGNAMES + OFN_PATHMUSTEXIST, _
Optional I_strTitre As String = vbNullString, _
Optional I_strInitFile As String = vbNullString, _
Optional I_strInitDir As String = vbNullString, _
Optional I_strDefautExt As String = vbNullString) As String
Dim tyDialog As OPENFILENAME
Dim lngRep As Long
On Error GoTo Err_Handler
tyDialog.lStructSize = Len(tyDialog)
tyDialog.hwndOwner = I_lngHwnd ' Handle du propriétraire de la fenêtre.
tyDialog.hInstance = App.hInstance
tyDialog.lpstrFilter = Replace(I_strFiltre, "|", vbNullChar) & vbNullChar & vbNullChar
tyDialog.lpstrCustomFilter = vbNullString ' Filtre personnalisé (non géré).
tyDialog.nMaxCustFilter = 0 ' Index de filtre personnalisé (non géré).
tyDialog.nFilterIndex = I_lngIdxFiltre ' Index du filtre à utiliser par défaut.
' Nom de fichier affiché à l'initialisation de la fenêtre.
tyDialog.lpstrFile = Left$(I_strInitFile & String$(1024, vbNullChar), 1024)
tyDialog.nMaxFile = Len(tyDialog.lpstrFile) - 1 ' Longueur du nom de fichier.
tyDialog.lpstrFileTitle = tyDialog.lpstrFile ' Nom et extension du fichier (sans chemin).
tyDialog.nMaxFileTitle = tyDialog.nMaxFile ' Taille de la chaîne précédente.
tyDialog.lpstrInitialDir = I_strInitDir ' Répertoire initial.
tyDialog.lpstrTitle = I_strTitre ' Titre de la fenêtre.
tyDialog.flags = I_lngFlags ' Flags pour affichage de la fenêtre.
'tyDialog.nFileOffset ' Position du nom du fichier dans la chaîne.
'tyDialog.nFileExtension ' Position de l'extension du fichier dans la chaîne.
' Extension par défaut ajoutée automatiquement si l'utilisateur l'oublie.
tyDialog.lpstrDefExt = I_strDefautExt
tyDialog.lCustData = 0
tyDialog.lpfnHook = 0
tyDialog.lpTemplateName = 0
' Affichage de la boîte de dialogue.
lngRep = GetOpenFileName(tyDialog)
' Retourne le nom long du fichier.
FichierOuvrir = Left$(tyDialog.lpstrFile, InStr(1, tyDialog.lpstrFile, vbNullChar) - 1)
Exit Function
Err_Handler:
'TO BE IMPLEMENTED
End Function |
Partager