• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 324
  • Last Modified:

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,            
     Dim sub3 As New Windows.Forms.ListViewItem.ListViewSubItem(fileItem, _
     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.
     nIndex = nIndex + 1
  End While
End Sub

Can anyone please help how to do this in VB.Net??
1 Solution
Mike TomlinsonMiddle School Assistant TeacherCommented:
The project here will show you how to do everything and anything you ever wanted to know about how to make a "windows explorer" type interface.  It is heavily commented and pretty easy to understand.



Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now