fischadler
Programmer
Hello folks,
I was trying to find a control that mimics the Windows Explorer (something like a suped up version FileListBox with file type icons and details etc). Having failed to find any, I resorted to write my own code using the ListView Control.
I managed to get the icon that windows explorer would display for each file type to be shown in a picturebox but I can't get it to an ImageList control so that it can be used by the ListView control. I am getting an error 481 "invalid picture" on the line that adds pictures to the ImageList (see code).
Is there some other way to do it? The code below uses SHGetFileInfo and ImageList_Draw APIs to get the file icon inside the picturebox.
Thanks!
-Fischadler
I was trying to find a control that mimics the Windows Explorer (something like a suped up version FileListBox with file type icons and details etc). Having failed to find any, I resorted to write my own code using the ListView Control.
I managed to get the icon that windows explorer would display for each file type to be shown in a picturebox but I can't get it to an ImageList control so that it can be used by the ListView control. I am getting an error 481 "invalid picture" on the line that adds pictures to the ImageList (see code).
Is there some other way to do it? The code below uses SHGetFileInfo and ImageList_Draw APIs to get the file icon inside the picturebox.
Thanks!
Code:
Private Const MAX_PATH = 260
Private Const SHGFI_DISPLAYNAME = &H200 ' get display name
Private Const SHGFI_EXETYPE = &H2000 ' return exe type
Private Const SHGFI_LARGEICON = &H0 ' get large icon
Private Const SHGFI_SHELLICONSIZE = &H4 ' get shell size icon
Private Const SHGFI_SMALLICON = &H1 ' get small icon
Private Const SHGFI_SYSICONINDEX = &H4000 ' get system icondex
Private Const SHGFI_TYPENAME = &H400 ' get type name
Private Const ILD_BLEND50 = &H4
Private Const ILD_BLEND25 = &H2
Private Const ILD_TRANSPARENT = &H1
Private Const CLR_NONE = &HFFFFFFFF
Private Const CLR_DEFAULT = &HFF000000
Private Type SHFILEINFO
hIcon As Long ' : icon
iIcon As Long ' : icondex
dwAttributes As Long ' : SFGAO_ flags
szDisplayName As String * MAX_PATH ' : display name (or path)
szTypeName As String * 80 ' : type name
End Type
Private Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" (ByVal pszPath As String, ByVal dwFileAttributes As Long, psfi As SHFILEINFO, ByVal cbFileInfo As Long, ByVal uFlags As Long) As Long
Private Declare Function ImageList_Draw Lib "comctl32.dll" (ByVal himl As Long, ByVal i As Long, ByVal hdcDst As Long, ByVal x As Long, ByVal y As Long, ByVal fStyle As Long) As Long
Private Declare Function ImageList_DrawEx Lib "comctl32.dll" (ByVal himl As Long, ByVal i As Long, ByVal hdcDst As Long, ByVal x As Long, ByVal y As Long, ByVal dx As Long, ByVal dy As Long, ByVal rgbBk As Long, ByVal rgbFg As Long, ByVal fStyle As Long) As Long
Private Sub Form_Load()
Dim hImage As Long, udtFI As SHFILEINFO
'get the handle of the system image list that contains the large icon images
hImage = SHGetFileInfo("c:\myfile.txt", ByVal 0&, udtFI, Len(udtFI), SHGFI_SYSICONINDEX Or SHGFI_LARGEICON)
Picture1.AutoRedraw = True
ImageList_Draw hImage, udtFI.iIcon, Picture1.hDC, 0, 0, ILD_TRANSPARENT
ImageList1.ListImages.Add 1, "fileico", Picture1.Picture
End Sub
-Fischadler