Objectif de ce code
-Récupérer le nom de ce ou ces fichiers.
-Récupérer la taille (en Ko) de ce ou ces fichiers.
-Récupérer l'icone de ce ou ces fichier
-Cadrer une colonne à droite.


Code : Tout sélectionner
; Drag one or multi files into the ListIconGadget
;
; Contributor : falsam
; OS : Windows
; Purebasic : 4.50++
Enumeration
#Mainform
#FileExplorer
EndEnumeration
Define.l Event, GEvent, TEvent
Global WindowStyle.i=#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered|#PB_Window_SizeGadget
Global DropFiles.s, N.i, FileName.s, FileSize.s, FileIcon.l
;Justify a column to the right, left Or center
;Cadrer une colonne à droite gauche ou au centre.
Procedure JustifyGadgetColumn(Gadget.l, Column.i, FMT.i)
Protected Lvc.LV_COLUMN
Lvc\Mask = #LVCF_FMT
Lvc\FMT = FMT ;#LVCFMT_LEFT or #LVCFMT_CENTER or #LVCFMT_RIGHT
SendMessage_(GadgetID(Gadget), #LVM_SETCOLUMN, Column, @Lvc)
EndProcedure
;Retrieves the icon associated to a file (By Goznal)
;Récupère l'icône associée à un fichier
Procedure GetAssociatedFileIcon(IconPath.s, IconSize)
Protected FileInfo.SHFILEINFO
; http://msdn.microsoft.com/en-us/library/bb762179%28VS.85%29.aspx
; IconSize peut prendre les valeur ci-dessous :
; IconSize can take the value :
; #SHGFI_SMALLICON -> small (usually 16x16) icon
; #SHGFI_LARGEICON -> large (usually 32x32) icon
; #SHGFI_SHELLICONSIZE -> shell default icon size
SHGetFileInfo_(IconPath, 0, @FileInfo, SizeOf(SHFILEINFO), #SHGFI_ICON | IconSize)
ProcedureReturn FileInfo\hIcon
EndProcedure
Procedure Open_MainForm()
OpenWindow(#Mainform, 0, 0, 500, 400, "Drag files into the ListIconGadget", WindowStyle)
ListIconGadget(#FileExplorer, 10, 10, 480, 380, "File", 300)
AddGadgetColumn(#FileExplorer, 1, "Size(Ko)", 60)
justifyGadgetColumn(#FileExplorer, 1, #LVCFMT_RIGHT)
EnableGadgetDrop(#FileExplorer, #PB_Drop_Files, #PB_Drag_Copy)
EndProcedure
Open_MainForm()
Repeat
Event = WaitWindowEvent(10)
GEvent = EventGadget()
TEvent = EventType()
Select Event
Case #PB_Event_Gadget
Select GEvent
EndSelect
Case #PB_Event_GadgetDrop
If GEvent = #FileExplorer
DropFiles = EventDropFiles()
For N=1 To CountString(DropFiles, Chr(10)) + 1
FileName = StringField(DropFiles, N, Chr(10)) ;Return file name
FileSize = StrF(FileSize(FileName)/1024, 1) ;Return file size
FileIcon = GetAssociatedFileIcon(FileName, #SHGFI_SMALLICON)
AddGadgetItem(#FileExplorer, GetGadgetState(#FileExplorer), FileName + Chr(10) + FileSize, FileIcon)
Next
EndIf
Case #PB_Event_CloseWindow
End
EndSelect
ForEver