Extracting and displaying folder icons

Posted on 2004-10-25
Last Modified: 2011-09-20
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??
Question by:uncivilizedpikinini
    1 Comment
    LVL 85

    Accepted Solution

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    The Complete Ruby on Rails Developer Course

    Ruby on Rails is one of the most popular web development frameworks, and a useful tool used by both startups and more established companies to build strong graphic user interfaces, and responsive websites and apps.

    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now