Private Declare Function ExtractIconEx Lib "shell32.dll" Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal nIconIndex As Int32, ByRef phiconLarge As IntPtr, ByRef phiconSmall As IntPtr, ByVal nIcons As Int32) As Int32
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
/// assuming you have a ListView , set to SmallIcon View & an ImageList tied to its smallimagelist
Dim path As String = "C:\Program Files\IconForge7\LEAVES.ICL" /// path to a valid .ICL file goes here.
/// to retreive the count of icons , use path , then index set to -1 , then 2 IntPtr.Zeros , then a 0 ...
Dim index As Int32 = ExtractIconEx(path, -1, IntPtr.Zero, IntPtr.Zero, 0)
/// if the count is greater than 0 ( meaning no icons ) ...
If index > 0 Then
For x As Int32 = 0 To index - 1
Dim icoLarge As IntPtr
Dim icoSmall As IntPtr
ExtractIconEx(path, x, icoLarge, icoSmall, 1)
/// lets add the small icon retreived from the index x
/// if you wanted to use LargeIcon view on your listview / wanted the large icons for any purpose , use icoLarge.
If Not icoSmall.Equals(IntPtr.Zero) Then
Dim i As Icon = Icon.FromHandle(icoSmall)
ImageList1.Images.Add(i)
Dim lvi As New ListViewItem("", x)
ListView1.Items.Add(lvi)
End If
/// move on to the next indexed icon in the .ICL file
Next
End If
End Sub