Link to home
Start Free TrialLog in
Avatar of uncivilizedpikinini
uncivilizedpikinini

asked on

Extracting and displaying folder icons

Hi everyone,

I'm having a problem to extract the "Folder Icon" on the disk drive, the only icon can be displayed on the list view is the file icon. Here is a part of my code:

Private Sub ShowFiles()
  Dim dir() As String
  Dim en As System.Collections.IEnumerator
  Dim myIcon As System.Drawing.Icon
  Dim shinfo As New SHFILEINFO
  Dim hImgSmall As IntPtr
  Dim hImgLarge As IntPtr
  Dim fName As String
  Dim fSize As String
  Dim fType As String
  Dim fModified As String

  dir = System.IO.Directory.GetFiles(cboxDrives.Text)
  lvwFiles.SmallImageList = ImageList2
  lvwFiles.LargeImageList = ImageList2
  shinfo.szDisplayName = New String(Chr(0), 260)
  shinfo.szTypeName = New String(Chr(0), 80)
  en = dir.GetEnumerator
 
  While en.MoveNext
     fName = CStr(en.Current)
     Dim fInfo As New System.IO.FileInfo(fName)
     fSize = Str(Math.Ceiling(fInfo.Length / 1024))
     fType = fInfo.Extension
     fModified = fInfo.LastWriteTime
     Dim fileItem As New Windows.Forms.ListViewIte(GetNameFromPathAndName _
                                      (fName), nIndex)
     Dim sub1 As New Windows.Forms.ListViewItem.ListViewSubItem(fileItem, _
                                          fSize + " KB")
     Dim sub2 As New Windows.Forms.ListViewItem.ListViewSubItem(fileItem,            
                                                     fType)
     Dim sub3 As New Windows.Forms.ListViewItem.ListViewSubItem(fileItem, _
                                                fModified)
     fileItem.SubItems.Add(sub1)
     fileItem.SubItems.Add(sub2)
     fileItem.SubItems.Add(sub3)
     hImgSmall = SHGetFileInfo(fName, 0, shinfo, Marshal.SizeOf(shinfo), _
                         SHGFI_ICON Or SHGFI_SMALLICON)
     myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon)
     ImageList2.Images.Add(myIcon) 'Add icon to imageList.
     lvwFiles.Items.Add(fileItem)
     nIndex = nIndex + 1
  End While
End Sub

Can anyone please help how to do this in VB.Net??
Thanks,
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial