Problem using ExtractIconEx with ListView 
Author Message
 Problem using ExtractIconEx with ListView

I am trying to get The ExtractIconEx API call to work.  I have
successfully taken the images and placed them in a picturebox and them
used the image property to move the image to a imagelist control.  

The problem I am having is that on the standard icons I seem to be losing
the last row of pixels, and on the small Icons they are much smaller than
the small icons in the Explorer Shell.  They appear to be 8x8.  The code
I am using to do this follows:

' Extract Icons
hIcon = ExtractIconEx(pszFileName$, niIndex, hLargeIcon, hSmallIcon, 1)

' Put Icons into imagelists
niResult = DrawIconEx(picIcon.hdc, 0, 0, hSmallIcon, 16, 16, 0, _
        nlBrush, DI_IMAGE)
ilstSmall.ListImages.Add 1, .OLEType, picIcon.Image
niResult = DrawIconEx(picIcon.hdc, 0, 0, hLargeIcon, 32, 32, 0, _
        nlBrush, DI_IMAGE)
ilstLarge.ListImages.Add 1, .OLEType, picIcon.Image

Is this the appropriate method for getting icons and putting them into an
image list?  Is there a better way?  and Why am I having this strang
problem with then small icons?

Is GetAssociatedIcon a better choice?

Thanks in advance,

James Moore
Sr Systems Developer,
Nabisco



Sun, 31 Oct 1999 03:00:00 GMT  
 Problem using ExtractIconEx with ListView

Hi James!

Here is some code I just cut out of my project. Its not ready for running
(some variables may not be declared) but I think you see how it works.

=====================================
'This code do I have in a separet module

Private Declare Function GetClassWord Lib "User32" (ByVal hWnd As Long,
ByVal nIndex As Long) As Long
Private Declare Function ExtractIcon Lib "SHELL32" Alias "ExtractIconA"
(ByVal hInst As Long, ByVal lpszexename As String, ByVal hIcon As Long) As
Long
Private Declare Function DrawIcon Lib "User32" (ByVal hDC As Long, ByVal x
As Long, ByVal y As Long, ByVal hIcon As Long) As Long

Private Const GCW_HMODULE = (-16)

Public Function GetIcon(strFileName As String, picPictureControl As Object,
lnghWnd As Long) As Boolean

    'H?mtar ikonen i program

    Dim myhInst As Long, hIcon As Long
    Dim r As Long

      GetIcon = True

      picPictureControl.Picture = LoadPicture("") ' Clear the previous
image.

      myhInst = GetClassWord(lnghWnd, GCW_HMODULE)

      ' Get handle to icon.
      hIcon = ExtractIcon(myhInst, strFileName, 0)

      If hIcon = 0 Then
        GetIcon = False
        Exit Function
      End If

      picPictureControl.AutoRedraw = -1  ' Make the picture's hDC point to
the
                                ' persistent bitmap.
      r = DrawIcon(picPictureControl.hDC, 0, 0, hIcon)
      picPictureControl.Refresh  ' Cause Windows to paint from the
persistent bitmap
                        ' to show the icon.

End Function
=============================================
'This is the code that puts the icon in a imagelist

    Dim twpX, twpY As Long

    twpX = Screen.TwipsPerPixelX
    twpY = Screen.TwipsPerPixelY

    frmMain.picImage.Width = 32 * twpX
    frmMain.picImage.Height = 32 * twpY

    frmMain.picIcon.Width = 32 * twpX
    frmMain.picIcon.Height = 32 * twpY

RetVal = GetIcon(cmdline, frmMain.picIcon, frmMain.hWnd)
                If RetVal = True Then
                    frmMain.picImage.Picture = LoadPicture("")
                    frmMain.picImage.CurrentY = 0
                    frmMain.picImage.CurrentX = 0
                    frmMain.picImage.Picture = frmMain.picIcon.Image
                    Set imgX = frmMain.imglstIcons.ListImages.Add(, ,
frmMain.picImage.Picture)

=============================================

As you see I have two pictureboxes, I paint in one and then moves that
first to another picturebox and then to the imageslist. This works fine,
remeber to use maskcolor to white (or what color you have for backround in
the control you have the listimage connected to).

Hope this helps!

/Patrik



Quote:
> I am trying to get The ExtractIconEx API call to work.  I have
> successfully taken the images and placed them in a picturebox and them
> used the image property to move the image to a imagelist control.  

> The problem I am having is that on the standard icons I seem to be losing
> the last row of pixels, and on the small Icons they are much smaller than
> the small icons in the Explorer Shell.  They appear to be 8x8.  The code
> I am using to do this follows:

> ' Extract Icons
> hIcon = ExtractIconEx(pszFileName$, niIndex, hLargeIcon, hSmallIcon, 1)

> ' Put Icons into imagelists
> niResult = DrawIconEx(picIcon.hdc, 0, 0, hSmallIcon, 16, 16, 0, _
>    nlBrush, DI_IMAGE)
> ilstSmall.ListImages.Add 1, .OLEType, picIcon.Image
> niResult = DrawIconEx(picIcon.hdc, 0, 0, hLargeIcon, 32, 32, 0, _
>    nlBrush, DI_IMAGE)
> ilstLarge.ListImages.Add 1, .OLEType, picIcon.Image

> Is this the appropriate method for getting icons and putting them into an
> image list?  Is there a better way?  and Why am I having this strang
> problem with then small icons?

> Is GetAssociatedIcon a better choice?

> Thanks in advance,

> James Moore
> Sr Systems Developer,
> Nabisco



Mon, 01 Nov 1999 03:00:00 GMT  
 Problem using ExtractIconEx with ListView

You forgot.  James D. Moore was using ExtractIconEx, not ExtractIcon.

--
James Johnston



Quote:
> Hi James!

> Here is some code I just cut out of my project. Its not ready for running
> (some variables may not be declared) but I think you see how it works.

> =====================================
> 'This code do I have in a separet module

> Private Declare Function GetClassWord Lib "User32" (ByVal hWnd As Long,
> ByVal nIndex As Long) As Long
> Private Declare Function ExtractIcon Lib "SHELL32" Alias "ExtractIconA"
> (ByVal hInst As Long, ByVal lpszexename As String, ByVal hIcon As Long)
As
> Long
> Private Declare Function DrawIcon Lib "User32" (ByVal hDC As Long, ByVal
x
> As Long, ByVal y As Long, ByVal hIcon As Long) As Long

> Private Const GCW_HMODULE = (-16)

> Public Function GetIcon(strFileName As String, picPictureControl As
Object,
> lnghWnd As Long) As Boolean

>     'H?mtar ikonen i program

>     Dim myhInst As Long, hIcon As Long
>     Dim r As Long

>       GetIcon = True

>       picPictureControl.Picture = LoadPicture("") ' Clear the previous
> image.

>       myhInst = GetClassWord(lnghWnd, GCW_HMODULE)

>       ' Get handle to icon.
>       hIcon = ExtractIcon(myhInst, strFileName, 0)

>       If hIcon = 0 Then
>         GetIcon = False
>         Exit Function
>       End If

>       picPictureControl.AutoRedraw = -1  ' Make the picture's hDC point
to
> the
>                                 ' persistent bitmap.
>       r = DrawIcon(picPictureControl.hDC, 0, 0, hIcon)
>       picPictureControl.Refresh  ' Cause Windows to paint from the
> persistent bitmap
>                         ' to show the icon.

> End Function
> =============================================
> 'This is the code that puts the icon in a imagelist

>     Dim twpX, twpY As Long

>     twpX = Screen.TwipsPerPixelX
>     twpY = Screen.TwipsPerPixelY

>     frmMain.picImage.Width = 32 * twpX
>     frmMain.picImage.Height = 32 * twpY

>     frmMain.picIcon.Width = 32 * twpX
>     frmMain.picIcon.Height = 32 * twpY

> RetVal = GetIcon(cmdline, frmMain.picIcon, frmMain.hWnd)
>                 If RetVal = True Then
>                     frmMain.picImage.Picture = LoadPicture("")
>                     frmMain.picImage.CurrentY = 0
>                     frmMain.picImage.CurrentX = 0
>                     frmMain.picImage.Picture = frmMain.picIcon.Image
>                     Set imgX = frmMain.imglstIcons.ListImages.Add(, ,
> frmMain.picImage.Picture)

> =============================================

> As you see I have two pictureboxes, I paint in one and then moves that
> first to another picturebox and then to the imageslist. This works fine,
> remeber to use maskcolor to white (or what color you have for backround
in
> the control you have the listimage connected to).

> Hope this helps!

> /Patrik



> > I am trying to get The ExtractIconEx API call to work.  I have
> > successfully taken the images and placed them in a picturebox and them
> > used the image property to move the image to a imagelist control.  

> > The problem I am having is that on the standard icons I seem to be
losing

> > the last row of pixels, and on the small Icons they are much smaller
than

> > the small icons in the Explorer Shell.  They appear to be 8x8.  The
code
> > I am using to do this follows:

> > ' Extract Icons
> > hIcon = ExtractIconEx(pszFileName$, niIndex, hLargeIcon, hSmallIcon, 1)

> > ' Put Icons into imagelists
> > niResult = DrawIconEx(picIcon.hdc, 0, 0, hSmallIcon, 16, 16, 0, _
> >       nlBrush, DI_IMAGE)
> > ilstSmall.ListImages.Add 1, .OLEType, picIcon.Image
> > niResult = DrawIconEx(picIcon.hdc, 0, 0, hLargeIcon, 32, 32, 0, _
> >       nlBrush, DI_IMAGE)
> > ilstLarge.ListImages.Add 1, .OLEType, picIcon.Image

> > Is this the appropriate method for getting icons and putting them into
an

> > image list?  Is there a better way?  and Why am I having this strang
> > problem with then small icons?

> > Is GetAssociatedIcon a better choice?

> > Thanks in advance,

> > James Moore
> > Sr Systems Developer,
> > Nabisco



Mon, 01 Nov 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Problem using ExtractIconEx with ListView

2. Problem using ExtractIconEx with ListView

3. Problem using ExtractIconEx with ListView

4. Problem using ListView and TreeView in Access 2000

5. VB5: Problems with Listview ColumnHeaders at design-time (using Service Pack 1)

6. Problem sorting listview using LVM_SORTITEMS

7. VB5: Problems with Listview ColumnHeaders at design-time (using Service Pack 1)

8. ExtractIconEx

9. ExtractIconEx

10. ExtractIconEx?

11. ExtractIconEx: Heavily Guarded Secret

12. ExtractIconEx API call (VB4/Win95)

 

 
Powered by phpBB® Forum Software