ExtractIcon with a VB ImageList Control 
Author Message
 ExtractIcon with a VB ImageList Control

Maybe you can modify this to stick the icons into an imagelist control.

------
Option Explicit

Public Const MAX_PATH = 260
Public Const SHGFI_DISPLAYNAME = &H200
Public Const SHGFI_EXETYPE = &H2000
Public Const SHGFI_SYSICONINDEX = &H4000 'system icon index
Public Const SHGFI_LARGEICON = &H0 'large icon
Public Const SHGFI_SMALLICON = &H1 'small icon
Public Const ILD_TRANSPARENT = &H1 'display transparent
Public Const SHGFI_SHELLICONSIZE = &H4
Public Const SHGFI_TYPENAME = &H400
Public Const BASIC_SHGFI_FLAGS = SHGFI_TYPENAME Or SHGFI_SHELLICONSIZE Or
SHGFI_SYSICONINDEX Or SHGFI_DISPLAYNAME Or SHGFI_EXETYPE

Public Type SHFILEINFO
    hIcon As Long
    iIcon As Long
    dwAttributes As Long
    szDisplayName As String * MAX_PATH
    szTypeName As String * 80
End Type

Public Declare Function SHGetFileInfo Lib "shell32.dll" Alias
"SHGetFileInfoA" (ByVal pszPath As String, ByVal dwFileAttributes As Long,
psfi As SHFILEINFO, ByVal cbSizeFileInfo As Long, ByVal uFlags As Long) As
Long
Public Declare Function ImageList_Draw Lib "comctl32.dll" (ByVal himl&,
ByVal i&, ByVal hDCDest&, ByVal x&, ByVal Y&, ByVal flags&) As Long
Public shinfo As SHFILEINFO

Sub Get16Icon(pic As PictureBox, fName As String)
    Dim r As Long
    Dim hImgSmall As Long
    Dim fnFilter As String

    pic.Picture = LoadPicture()
    pic.AutoRedraw = True

    hImgSmall& = SHGetFileInfo(fName$, 0&, shinfo, Len(shinfo),
BASIC_SHGFI_FLAGS Or SHGFI_SMALLICON)

    r& = ImageList_Draw(hImgSmall&, shinfo.iIcon, pic.hDC, 0, 0,
ILD_TRANSPARENT)
    pic.Picture = pic.Image

End Sub

------

Quote:

>I have a standard ImageList Control in VB 5 and I need to populate it at
>runtime with images. OK this is easy using LoadRes... whatever, but I need
>to extract icons from the system dll's eg system32.dll. How can I do
>this???

>I know you can use API calls (ExtractIcon) to get an icon, but this only
>returns a handle to the icon and the imagelist control cannot accept this.
>Can I coerce it??

>I have tried creating an ImageList in code using comclt32 API calls, but I
>can not then get the common controls (treeview/listview) to accept this as
>a valid ImageList Object. I am sure this can be done, but what am I
>missing?

>Any help would be appreciated,

>Thanks for your time

>Sam Mercer




Sat, 14 Oct 2000 03:00:00 GMT  
 ExtractIcon with a VB ImageList Control

I have a standard ImageList Control in VB 5 and I need to populate it at
runtime with images. OK this is easy using LoadRes... whatever, but I need
to extract icons from the system dll's eg system32.dll. How can I do
this???

I know you can use API calls (ExtractIcon) to get an icon, but this only
returns a handle to the icon and the imagelist control cannot accept this.
Can I coerce it??

I have tried creating an ImageList in code using comclt32 API calls, but I
can not then get the common controls (treeview/listview) to accept this as
a valid ImageList Object. I am sure this can be done, but what am I
missing?

Any help would be appreciated,

Thanks for your time

Sam Mercer



Sun, 15 Oct 2000 03:00:00 GMT  
 ExtractIcon with a VB ImageList Control

Samuel,
   You may want to use the DrawIcon API along with ExtractIcon. It takes
the handle returned by ExtractIcon to actually draw the picture.  I have
used it to draw an icon on a form and in a PictureBox.  I have not tried
it with any other controls
-Dave

Quote:

> I have a standard ImageList Control in VB 5 and I need to populate it at
> runtime with images. OK this is easy using LoadRes... whatever, but I need
> to extract icons from the system dll's eg system32.dll. How can I do
> this???

> I know you can use API calls (ExtractIcon) to get an icon, but this only
> returns a handle to the icon and the imagelist control cannot accept this.
> Can I coerce it??

> I have tried creating an ImageList in code using comclt32 API calls, but I
> can not then get the common controls (treeview/listview) to accept this as
> a valid ImageList Object. I am sure this can be done, but what am I
> missing?

> Any help would be appreciated,

> Thanks for your time

> Sam Mercer




Sun, 15 Oct 2000 03:00:00 GMT  
 ExtractIcon with a VB ImageList Control

Samuel,

Quote:
> I have a standard ImageList Control in VB 5 and I need to populate it at
> runtime with images. OK this is easy using LoadRes... whatever, but I need
> to extract icons from the system dll's eg system32.dll. How can I do
> this???

> I know you can use API calls (ExtractIcon) to get an icon, but this only
> returns a handle to the icon and the imagelist control cannot accept this.
> Can I coerce it??

:-) Yeah, only if you ask it real nicely. Actually try the code below that
converts an icon handle to a picture object which can then be passed
as the Picture param of a ListImage's Add method. BTW it's a derivation
of the code found in MS KB article ID Q141933 (or Q161299) "HOWTO:
VB4: Capture and Print the Screen,  a Form, or any Window". Sorry,
don't have the URL...

' ============================================

' Code module declares

Type GUID
  Data1 As Long
  Data2 As Integer
  Data3 As Integer
  Data4(7) As Byte
End Type

Type PICTDESC
   cbSize As Long
   picType As Long   ' one of VB's PictureTypeConstants
   hImage As Long    ' HBITMAP, HMETAFILE, HICON, HENHMETAFILE
   Data1 As Long      ' HBITMAP hpal, HMETAFILE xExt
   Data2 As Long      ' HMETAFILE yExt
End Type

' Note that IPicture is a hidden interface implemented by the
' OLE Automation type library Stdole2.tlb. You will need to add
' a project reference to the typelib in order to use this function.
Declare Function OleCreatePictureIndirect Lib "olepro32.dll" _
                            (pPictDesc As PICTDESC, _
                            RefIID As GUID, _
                            ByVal fPictureOwnsHandle As Long, _
                            ppvObj As IPicture) As Long

Public Const S_OK = 0   ' indicates successful HRESULT

' ============================================

' Creates a picture object from an image handle
'   hImage      - either a HBITMAP, HMETAFILE, HICON or HENHMETAFILE
'   dwPicType - one of VB's PictureTypeConstants describing the hImage param.

' Returns a VB Picture object on success, or the object value "Nothing" otherwise.

Public Function GetPicture(hImage As Long, _
                                        dwPicType As PictureTypeConstants) As Picture
  Dim pd As PICTDESC
  Dim IID_IDispatch As GUID
  Dim objPic As Picture

  If hImage = 0 Then Exit Function

  ' Fill the picture description struct
  With pd
    .cbSize = Len(pd)         ' must specify the struct's size
    .picType = dwPicType   ' vbPicTypeIcon
    .hImage = hImage
  End With

  ' Fill the IDispatch Interface ID, {00020400-0000-0000-C000-000000046}
  With IID_IDispatch
    .Data1 = &H20400
    .Data4(0) = &HC0
    .Data4(7) = &H46
  End With

  ' Create the Picture object
  If OleCreatePictureIndirect(pd, IID_IDispatch, True, objPic) = S_OK Then
    Set GetPicture = objPic
  End If

End Function

Quote:
> I have tried creating an ImageList in code using comclt32 API calls, but I
> can not then get the common controls (treeview/listview) to accept this as
> a valid ImageList Object. I am sure this can be done, but what am I
> missing?

Not so sure. Comctl32.ocx's imagelist is quite a different beast than
the imagelist control itself. As far as I know, Comctl32.ocx's listview
control will only talk to Comctl32.ocx's imagelist control. But if by
change you do figure something out, please post it here...

--
Brad Martinez
http://members.aol.com/btmtz/vb

Visit the new CCRP site at:
http://www.mvps.org/ccrp

Please direct questions/replies to the newsgroup.



Sun, 15 Oct 2000 03:00:00 GMT  
 ExtractIcon with a VB ImageList Control

If you can make the image list with the api's then I think you need to
use the api methods to tell the listview which imagelist to use
by using sendmessage.

if you use the vb methods on an api made (or filled) imagelist I don't think
vb knows how to use it.

LVSIL_STATE is not the const you need to set the normal imagelist,
and I am not positive what they are but most likely something like
LVSIL_NORMAL and LVSIL_SMALL

  SendMessageLong ListView.hwnd, LVM_SETIMAGELIST, LVSIL_STATE, ByVal
hImageList

Quote:

>Samuel,
>   You may want to use the DrawIcon API along with ExtractIcon. It takes
>the handle returned by ExtractIcon to actually draw the picture.  I have
>used it to draw an icon on a form and in a PictureBox.  I have not tried
>it with any other controls
>-Dave


>> I have a standard ImageList Control in VB 5 and I need to populate it at
>> runtime with images. OK this is easy using LoadRes... whatever, but I
need
>> to extract icons from the system dll's eg system32.dll. How can I do
>> this???

>> I know you can use API calls (ExtractIcon) to get an icon, but this only
>> returns a handle to the icon and the imagelist control cannot accept
this.
>> Can I coerce it??

>> I have tried creating an ImageList in code using comclt32 API calls, but
I
>> can not then get the common controls (treeview/listview) to accept this
as
>> a valid ImageList Object. I am sure this can be done, but what am I
>> missing?

>> Any help would be appreciated,

>> Thanks for your time

>> Sam Mercer




Tue, 17 Oct 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. ExtractIcon with a VB ImageList Control

2. ExtractIcon with a VB ImageList Control

3. ExtractIcon with a VB ImageList Control

4. ExtractIcon with a VB ImageList Control

5. Imagelist ExtractIcon Method Compresses Image

6. VB 4.0: ImageList control

7. VB ImageList Control

8. Overlay 2 icons in ImageList control to assign to Treeview control node image

9. Populating an imagelist from an existing imagelist?

10. How: ImageList to System ImageList???

11. How to add an icon to a ImageList using the API "ExtractIcon"

12. How do I save an icon from ExtractIcon API to file or in an imagelist?

 

 
Powered by phpBB® Forum Software