Extract icons from icl files

torisch

Member
Joined
Jan 23, 2003
Messages
11
Location
Troms
Hi.

I have some icon libraries in form of icl-files.
Is there a way I can extract the icons directly from the icl-files to use on buttons and forms in my winforms applications? Im programming in VB.NET, but solutions for C# is OK too.

__
Tor Inge
 
you can use ExtractIconEx , heres a quick example i knocked together for you ...
Code:
    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
 
Back
Top