ExtractAssociatedIcon into ImageList?

ExtractAssociatedIcon into ImageList?

Post by Jon Anderso » Fri, 28 Dec 2001 07:22:09



Hi,

I am building an "Explorer" type view of files using the Listview control.
I would like it to display not only the file's name, etc, but also its
associated icon.  To use icons in the Listview control they must come from
an ImageList control. I can extract the associated icon and display it in a
PictureBox control.  My trouble is that when I try to add the picture to an
ImageList control I get an "Out of memory" error.  I suspect that perhaps my
original picture extracted from the associated icon is somehow corrupt but
that the PictureBox control overcomes it well enough to display the image,
however the ImageList control can't overcome it and fails.    Included below
are the function I am using to extract the associated icon and the notation
I am using in my attempt to add it to the ImageList.  If anyone has any
ideas about what I could be doing wrong, or should be doing, or ???

Any and all help truly appreciated.

Thanks, Jon Anderson

<snip>
Set Picture1.Picture = GetIconForFile("c:\foo.html")   ' works - IE icon
displays
Set o = ImageList1.ListImages.Add(,,GetIconForFile("c:\foo.html"))   '
fails - Out of memory
Set o = ImageList1.ListImages.Add(,,Picture1.Picture)   ' also fails - Out
of memory
<snip>

Public Function GetIconForFile(ByVal sFileName As String) As IPictureDisp

    Dim hIcon As Long
    Dim Pic As PicBmp
    Dim IPic As IPicture
    Dim IID_IDispatch As GUID

    hIcon = ExtractAssociatedIcon(App.hInstance, sFileName, 2)
    If (hIcon > 0) Then
        ' Fill in with IDispatch Interface ID.
        With IID_IDispatch
            .Data1 = &H20400
            .Data4(0) = &HC0
            .Data4(7) = &H46
        End With
        ' Fill Pic with necessary parts.
        With Pic
            .Size = Len(Pic) ' Length of structure.
            .Type = vbPicTypeIcon ' Type of Picture (bitmap).
            .hBmp = hIcon ' Handle to bitmap.
        End With

        ' Create Picture object.
        Call OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)

        ' Return the new Picture object.
        Set GetIconForFile = IPic

        Call DestroyIcon(hIcon)
    End If
End Function

 
 
 

ExtractAssociatedIcon into ImageList?

Post by Tom E » Fri, 28 Dec 2001 09:14:48


Quote:>...I can extract the associated icon and display it in a
>PictureBox control.  My trouble is that when I try to add the picture to an
>ImageList control I get an "Out of memory" error...

Yeah, not only will that put a severe drain on system resources, it's
slow. A ~much~ better way to do this is to use ShGetFileInfo to obtain
a handle to the system image list and assign it to the listview.
ShGetFileInfo can also be used to retreive the system imagelist index
for particular file or type (as well as other useful info).
See these sites for some examples:
        http://www.mvps.org/btmtz/
        http://vbaccelerator.com/

On Wed, 26 Dec 2001 14:22:09 -0800, "Jon Anderson"


>Hi,

>I am building an "Explorer" type view of files using the Listview control.
>I would like it to display not only the file's name, etc, but also its
>associated icon.  To use icons in the Listview control they must come from
>an ImageList control. I can extract the associated icon and display it in a
>PictureBox control.  My trouble is that when I try to add the picture to an
>ImageList control I get an "Out of memory" error.  I suspect that perhaps my
>original picture extracted from the associated icon is somehow corrupt but
>that the PictureBox control overcomes it well enough to display the image,
>however the ImageList control can't overcome it and fails.    Included below
>are the function I am using to extract the associated icon and the notation
>I am using in my attempt to add it to the ImageList.  If anyone has any
>ideas about what I could be doing wrong, or should be doing, or ???

>Any and all help truly appreciated.

>Thanks, Jon Anderson

><snip>
>Set Picture1.Picture = GetIconForFile("c:\foo.html")   ' works - IE icon
>displays
>Set o = ImageList1.ListImages.Add(,,GetIconForFile("c:\foo.html"))   '
>fails - Out of memory
>Set o = ImageList1.ListImages.Add(,,Picture1.Picture)   ' also fails - Out
>of memory
><snip>

>Public Function GetIconForFile(ByVal sFileName As String) As IPictureDisp

>    Dim hIcon As Long
>    Dim Pic As PicBmp
>    Dim IPic As IPicture
>    Dim IID_IDispatch As GUID

>    hIcon = ExtractAssociatedIcon(App.hInstance, sFileName, 2)
>    If (hIcon > 0) Then
>        ' Fill in with IDispatch Interface ID.
>        With IID_IDispatch
>            .Data1 = &H20400
>            .Data4(0) = &HC0
>            .Data4(7) = &H46
>        End With
>        ' Fill Pic with necessary parts.
>        With Pic
>            .Size = Len(Pic) ' Length of structure.
>            .Type = vbPicTypeIcon ' Type of Picture (bitmap).
>            .hBmp = hIcon ' Handle to bitmap.
>        End With

>        ' Create Picture object.
>        Call OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)

>        ' Return the new Picture object.
>        Set GetIconForFile = IPic

>        Call DestroyIcon(hIcon)
>    End If
>End Function

-Tom
(please post replies to the newsgroup)

 
 
 

ExtractAssociatedIcon into ImageList?

Post by Rocky Clar » Fri, 28 Dec 2001 10:22:16


You can also go to my website:
http://kath-rock.com/sourcecode.htm
and download the "File Finder" or "Image Viewer" code. Both projects use the
system ImageLists attached to a ListView. They both will also give you good
examples of how to obtain the rest of the info from the files for the
ListView.

HTH,
Rocky Clark (Kath-Rock Software)


Quote:> Hi,

> I am building an "Explorer" type view of files using the Listview control.
> I would like it to display not only the file's name, etc, but also its
> associated icon.  To use icons in the Listview control they must come from
> an ImageList control. I can extract the associated icon and display it in
a
> PictureBox control.  My trouble is that when I try to add the picture to
an
> ImageList control I get an "Out of memory" error.  I suspect that perhaps
my
> original picture extracted from the associated icon is somehow corrupt but
> that the PictureBox control overcomes it well enough to display the image,
> however the ImageList control can't overcome it and fails.    Included
below
> are the function I am using to extract the associated icon and the
notation
> I am using in my attempt to add it to the ImageList.  If anyone has any
> ideas about what I could be doing wrong, or should be doing, or ???

> Any and all help truly appreciated.

> Thanks, Jon Anderson

> <snip>
> Set Picture1.Picture = GetIconForFile("c:\foo.html")   ' works - IE icon
> displays
> Set o = ImageList1.ListImages.Add(,,GetIconForFile("c:\foo.html"))   '
> fails - Out of memory
> Set o = ImageList1.ListImages.Add(,,Picture1.Picture)   ' also fails - Out
> of memory
> <snip>

> Public Function GetIconForFile(ByVal sFileName As String) As IPictureDisp

>     Dim hIcon As Long
>     Dim Pic As PicBmp
>     Dim IPic As IPicture
>     Dim IID_IDispatch As GUID

>     hIcon = ExtractAssociatedIcon(App.hInstance, sFileName, 2)
>     If (hIcon > 0) Then
>         ' Fill in with IDispatch Interface ID.
>         With IID_IDispatch
>             .Data1 = &H20400
>             .Data4(0) = &HC0
>             .Data4(7) = &H46
>         End With
>         ' Fill Pic with necessary parts.
>         With Pic
>             .Size = Len(Pic) ' Length of structure.
>             .Type = vbPicTypeIcon ' Type of Picture (bitmap).
>             .hBmp = hIcon ' Handle to bitmap.
>         End With

>         ' Create Picture object.
>         Call OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)

>         ' Return the new Picture object.
>         Set GetIconForFile = IPic

>         Call DestroyIcon(hIcon)
>     End If
> End Function

 
 
 

ExtractAssociatedIcon into ImageList?

Post by Rocky Clar » Mon, 31 Dec 2001 08:31:33


By the way, any new music in the works? <grin>


Quote:> Hi,

> I am building an "Explorer" type view of files using the Listview control.
> I would like it to display not only the file's name, etc, but also its
> associated icon.  To use icons in the Listview control they must come from
> an ImageList control. I can extract the associated icon and display it in
a
> PictureBox control.  My trouble is that when I try to add the picture to
an
> ImageList control I get an "Out of memory" error.  I suspect that perhaps
my
> original picture extracted from the associated icon is somehow corrupt but
> that the PictureBox control overcomes it well enough to display the image,
> however the ImageList control can't overcome it and fails.    Included
below
> are the function I am using to extract the associated icon and the
notation
> I am using in my attempt to add it to the ImageList.  If anyone has any
> ideas about what I could be doing wrong, or should be doing, or ???

> Any and all help truly appreciated.

> Thanks, Jon Anderson

> <snip>
> Set Picture1.Picture = GetIconForFile("c:\foo.html")   ' works - IE icon
> displays
> Set o = ImageList1.ListImages.Add(,,GetIconForFile("c:\foo.html"))   '
> fails - Out of memory
> Set o = ImageList1.ListImages.Add(,,Picture1.Picture)   ' also fails - Out
> of memory
> <snip>

> Public Function GetIconForFile(ByVal sFileName As String) As IPictureDisp

>     Dim hIcon As Long
>     Dim Pic As PicBmp
>     Dim IPic As IPicture
>     Dim IID_IDispatch As GUID

>     hIcon = ExtractAssociatedIcon(App.hInstance, sFileName, 2)
>     If (hIcon > 0) Then
>         ' Fill in with IDispatch Interface ID.
>         With IID_IDispatch
>             .Data1 = &H20400
>             .Data4(0) = &HC0
>             .Data4(7) = &H46
>         End With
>         ' Fill Pic with necessary parts.
>         With Pic
>             .Size = Len(Pic) ' Length of structure.
>             .Type = vbPicTypeIcon ' Type of Picture (bitmap).
>             .hBmp = hIcon ' Handle to bitmap.
>         End With

>         ' Create Picture object.
>         Call OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)

>         ' Return the new Picture object.
>         Set GetIconForFile = IPic

>         Call DestroyIcon(hIcon)
>     End If
> End Function

 
 
 

ExtractAssociatedIcon into ImageList?

Post by Jon Anderso » Sat, 05 Jan 2002 02:42:30


Rocky,

First of, thanks for your help.  Regarding new music.... Well, I wish I
could tell you it was so, but alas, it isn't me.

Thanks again,
Jon


> By the way, any new music in the works? <grin>



> > Hi,

> > I am building an "Explorer" type view of files using the Listview
control.
> > I would like it to display not only the file's name, etc, but also its
> > associated icon.  To use icons in the Listview control they must come
from
> > an ImageList control. I can extract the associated icon and display it
in
> a
> > PictureBox control.  My trouble is that when I try to add the picture to
> an
> > ImageList control I get an "Out of memory" error.  I suspect that
perhaps
> my
> > original picture extracted from the associated icon is somehow corrupt
but
> > that the PictureBox control overcomes it well enough to display the
image,
> > however the ImageList control can't overcome it and fails.    Included
> below
> > are the function I am using to extract the associated icon and the
> notation
> > I am using in my attempt to add it to the ImageList.  If anyone has any
> > ideas about what I could be doing wrong, or should be doing, or ???

> > Any and all help truly appreciated.

> > Thanks, Jon Anderson

> > <snip>
> > Set Picture1.Picture = GetIconForFile("c:\foo.html")   ' works - IE icon
> > displays
> > Set o = ImageList1.ListImages.Add(,,GetIconForFile("c:\foo.html"))   '
> > fails - Out of memory
> > Set o = ImageList1.ListImages.Add(,,Picture1.Picture)   ' also fails -
Out
> > of memory
> > <snip>

> > Public Function GetIconForFile(ByVal sFileName As String) As
IPictureDisp

> >     Dim hIcon As Long
> >     Dim Pic As PicBmp
> >     Dim IPic As IPicture
> >     Dim IID_IDispatch As GUID

> >     hIcon = ExtractAssociatedIcon(App.hInstance, sFileName, 2)
> >     If (hIcon > 0) Then
> >         ' Fill in with IDispatch Interface ID.
> >         With IID_IDispatch
> >             .Data1 = &H20400
> >             .Data4(0) = &HC0
> >             .Data4(7) = &H46
> >         End With
> >         ' Fill Pic with necessary parts.
> >         With Pic
> >             .Size = Len(Pic) ' Length of structure.
> >             .Type = vbPicTypeIcon ' Type of Picture (bitmap).
> >             .hBmp = hIcon ' Handle to bitmap.
> >         End With

> >         ' Create Picture object.
> >         Call OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)

> >         ' Return the new Picture object.
> >         Set GetIconForFile = IPic

> >         Call DestroyIcon(hIcon)
> >     End If
> > End Function

 
 
 

1. Transparent color in ImageList/ImageList Editor

I have create several icons with the image editor that came with BC++. I
choose the aqua color (with the red squiggle line through it) as the
transparent color. They work fine when I don't use them with ImageList.
I have beat the keyboard silly trying to use the ImageList Editor to
choose the correct transparent color. I tried clAqua as the transparent
color and white also became transparent. Any Ideas?

TIA
-Ben the confounded :-}

2. camera flythrough

3. ExtractAssociatedIcon

4. HELP! Format Converters...

5. ExtractAssociatedIcon and ListView

6. new fonts ??????

7. API: ExtractAssociatedIcon Error etc.

8. ExtractAssociatedIcon

9. ExtractAssociatedIcon() to picture object?

10. ExtractAssociatedIcon

11. Something Like ExtractAssociatedIcon