drag and drop filer
Jeg har følgende lille program, som gør det muligt at trække filer fra skrivebordet og ind på min form. Filnavnet skrives i listview og ikonet tegnes på min form.Men jeg kunne godt tænke mig at få filens ikon ind i min listview sammen med filnavnet.
Men hvordan gør man det? Har prøvet at rode lidt med en imagelist uden held.
'*** module1
Public Const DI_MASK = &H1
Public Const DI_IMAGE = &H2
Public Const DI_NORMAL = DI_MASK Or DI_IMAGE
Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias "ExtractAssociatedIconA" (ByVal hInst As Long, ByVal lpIconPath As String, lpiIcon As Long) As Long
Declare Function DrawIconEx Lib "user32" (ByVal hdc As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
'*** form
Private Sub Form_Load()
Form1.OLEDropMode = 1
End Sub
Private Sub Form_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
While Data.Files.Count > 0 ' Så længe der er filer at hente
mIcon = ExtractAssociatedIcon(App.hInstance, Data.Files(1), 2)
DrawIconEx Form1.hdc, 0, 0, mIcon, 0, 0, 0, 0, DI_NORMAL
Set imgobj = ListView1.ListItems.Add(, , Data.Files(1), , 1)
DestroyIcon mIcon
Data.Files.Remove (1)
Wend
End Sub