Ce code sert a enregistrer un Gif, Jpg, Bmp à l'endroit ou la personne le desire !
Mais il camoufle une fonction pour copier donc il copie un fichier donc ça marche car il n'est pas modifié par le programme comme les fonctions pour enregistrer les PictureBox
------>
Pour ce faire vous avez besoin:
- d'un module
- un form bien sur
- un bouton ici appellé Command1
- d'un picture box si vous voulez montrer à l'utilisateur l'image à enregistrer ici appellé Picture 1 à qui vous y mettre la propriété Picture l'image à afficher.
- d'un common dialog (Allez dans component/Microsoft Common Dialog Controls 6.0 (SP3)) ici appellé cm1
Source / Exemple :
' À ÉCRIRE DANS LE MODULE
'Declarations
Public Const FO_COPY = &H2
Public Const FO_DELETE = &H3
Public Const FO_MOVE = &H1
Public Const FO_RENAME = &H4
Public Const FOF_CONFIRMMOUSE = &H2
Public Const FOF_ALLOWUNDO = &H40
Public Const FOF_FILESONLY = &H80
Public Const FOF_MULTIDESTFILES = &H1
Public Const FOF_NOCONFIRMATION = &H10
Public Const FOF_NOCONFIRMMKDIR = &H200
Public Const FOF_NO_CONNECTED_ELEMENTS = &H1000
Public Const FOF_NOCOPYSECURITYATTRIBS = &H800
Public Const FOF_NOERRORUI = &H400
Public Const FOF_RENAMEONCOLLISION = &H8
Public Const FOF_SILENT = &H4
Public Const FOF_SIMPLEPROGRESS = &H100
Public Const FOF_WANTMAPPINGHANDLE = &H20
Public Const FOF_WANTNUKEWARNING = &H2000
Public Const FOF_NORECURSION = &H1000
Public Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String
End Type
Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" _
(Dest As Any, Sourc As Any, ByVal Length As Long)
Public Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" _
(lpFileOp As Any) As Long
Public Function copier(FROM As String, copie As String)
On Error GoTo erreur
Dim fso, msg
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(FROM) Then 'on verifie si le fichier existe
copier = "Le fichier n'existe pas"
Exit Function
erreur:
copier = "Une erreur c'est produite"
Exit Function
End If
Dim fos As SHFILEOPSTRUCT
Dim retval As Long
With fos
.hWnd = 0 'ou Me.hWnd si on a une Feuille par exemple
.wFunc = FO_COPY 'Action == Copie
.pFrom = FROM & vbNullChar 'Source path
.pTo = copie & vbNullChar 'Dest Path
.fFlags = FOF_NOCONFIRMMKDIR Or FOF_WANTMAPPINGHANDLE 'Flags de Copie
.fAnyOperationsAborted = 0
.hNameMappings = 0
.lpszProgressTitle = vbNullChar
End With
retval = SHFileOperation(fos)
copier = "OK"
End Function
'À ÉCRIRE DANS LE FORM
Private Sub Command1_Click()
On Error GoTo bug
cd1.DialogTitle = "Enregisterer l'image sous"
cd1.Filter = "Format GIF|*.gif"
cd1.FileName = "gauche.gif"
cd1.ShowSave
If cd1.FileName <> "" Then
resultat = copier(App.Path & "\images\gauche.gif", cd1.FileName)
If resultat = "OK" Then
MsgBox "Le fichier a été enrigistrer avec succés !"
Else
bug: MsgBox "Le fichier n'a pas été enrigistrer pour cause d'erreur"
End If
End If
End Sub
Conclusion :
Comme tout code, il y a de la place à amélioration. Si vous avez des idées, commentaires, critiques ne vous gênez pas à me les faire parvenir par la section commentaires.
Merci
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.