Icon in Imagelist


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Icon in Imagelist

  1. #1
    Brad Siemens Guest

    Icon in Imagelist

    I'm attempting to get the icon associated with a file and assign it to a
    Listitem in an imagelist control. I am using as my guide 'Retrieving an
    Associated 16x16 Icon Using SHGetFileInfo' from Randy Birch's VBnet. The
    example works to assign it to a picture box but try as I might, I can't seem
    to get it to associate with a ListItem.

    I have tried taking the picture and putting in an imagelist associated with
    the Listview control and it reports that it has been added, but when I
    assign the image to a Listitem nothing appears. No errors.

    Anyone have any idea how to accomplish this or am I tilting here?

    TIA
    Brad

    Public Function Set_FileIcon(oFile As cFile) As Long
    On Error GoTo ****

    Dim hImgSmall As Long

    'get the system icon associated with that file
    hImgSmall& = SHGetFileInfo(oFile.FullPath, 0&, _
    shinfo, Len(shinfo), _
    BASIC_SHGFI_FLAGS Or SHGFI_SMALLICON)

    oFile.Icon = shinfo.iIcon

    'draw the associated icon into the picturebox
    Call ImageList_Draw(hImgSmall&, shinfo.iIcon, _
    fOpen.Picture3.hDC, 0, 0, ILD_TRANSPARENT)

    If Not fOpen.Extension_Exists(oFile.Icon) Then
    fOpen.imlSmall.ListImages.Add , oFile.Icon, fOpen.Picture3.Image
    End If

    Exit Function
    ****:
    oErrors.LogToErrorFile Err.Number, "mFiles:Get_FileIcon(ByVal Path As
    String) As Long", Err.Description, Err.HelpFile, Err.HelpContext
    Err.Number = 0
    Resume Next
    End Function



  2. #2
    Larry Rebich Guest

    Re: Icon in Imagelist

    This is code that I use:

    Private Sub AddImageAndToItem(itm As ListItem, sFileName As String, ByRef
    sType As String)
    Dim tLarge As SHFILEINFO
    Dim tSmall As SHFILEINFO

    If ExtractIconIntoPictureUsingFile(sFileName, Me.Picture1(1), True,
    tLarge) Then
    With tLarge
    If .iIcon > 0 Then
    If NotExistInImageList(Me.imgLarge, .iIcon) Then
    imgLarge.ListImages.Add , "K" & .iIcon,
    Me.Picture1(1).Picture
    End If
    itm.Icon = "K" & .iIcon
    End If
    End With
    End If
    If ExtractIconIntoPictureUsingFile(sFileName, Me.Picture1(0), False,
    tSmall) Then
    With tSmall
    If .iIcon > 0 Then
    If NotExistInImageList(Me.imgSmall, .iIcon) Then
    imgSmall.ListImages.Add , "K" & .iIcon,
    Me.Picture1(0).Picture
    End If
    itm.SmallIcon = "K" & .iIcon
    End If
    End With
    End If
    sType = Trim$(tLarge.szTypeName)
    sType = UseExtIfBlank(sType, sFileName)
    End Sub

    Private Function UseExtIfBlank(sType As String, sFileName As String) As
    String
    ' 2000/02/01 Return the extension if no type
    Dim sFile As String
    Dim sExt As String
    If sType <> "" Then
    UseExtIfBlank = sType
    Else
    sExt = GetExtensionFromFileName(sFileName, sFile)
    If sExt <> "" Then
    sExt = UCase$(sExt) & " File"
    End If
    UseExtIfBlank = sExt
    End If
    End Function


    --
    Cheers,
    Larry Rebich

    More tips link to:
    http://www.buygold.net/tips

    Please:
    No personal e-mail questions :-)


    "Brad Siemens" <ebspc@sympatico.ca> wrote in message
    news:3b865ddd$1@news.devx.com...
    > I'm attempting to get the icon associated with a file and assign it to a
    > Listitem in an imagelist control. I am using as my guide 'Retrieving an
    > Associated 16x16 Icon Using SHGetFileInfo' from Randy Birch's VBnet. The
    > example works to assign it to a picture box but try as I might, I can't

    seem
    > to get it to associate with a ListItem.
    >
    > I have tried taking the picture and putting in an imagelist associated

    with
    > the Listview control and it reports that it has been added, but when I
    > assign the image to a Listitem nothing appears. No errors.
    >
    > Anyone have any idea how to accomplish this or am I tilting here?
    >
    > TIA
    > Brad
    >
    > Public Function Set_FileIcon(oFile As cFile) As Long
    > On Error GoTo ****
    >
    > Dim hImgSmall As Long
    >
    > 'get the system icon associated with that file
    > hImgSmall& = SHGetFileInfo(oFile.FullPath, 0&, _
    > shinfo, Len(shinfo), _
    > BASIC_SHGFI_FLAGS Or SHGFI_SMALLICON)
    >
    > oFile.Icon = shinfo.iIcon
    >
    > 'draw the associated icon into the picturebox
    > Call ImageList_Draw(hImgSmall&, shinfo.iIcon, _
    > fOpen.Picture3.hDC, 0, 0, ILD_TRANSPARENT)
    >
    > If Not fOpen.Extension_Exists(oFile.Icon) Then
    > fOpen.imlSmall.ListImages.Add , oFile.Icon, fOpen.Picture3.Image
    > End If
    >
    > Exit Function
    > ****:
    > oErrors.LogToErrorFile Err.Number, "mFiles:Get_FileIcon(ByVal Path As
    > String) As Long", Err.Description, Err.HelpFile, Err.HelpContext
    > Err.Number = 0
    > Resume Next
    > End Function
    >
    >




  3. #3
    Larry Rebich Guest

    Re: Icon in Imagelist

    This is code that I use:

    Private Sub AddImageAndToItem(itm As ListItem, sFileName As String, ByRef
    sType As String)
    Dim tLarge As SHFILEINFO
    Dim tSmall As SHFILEINFO

    If ExtractIconIntoPictureUsingFile(sFileName, Me.Picture1(1), True,
    tLarge) Then
    With tLarge
    If .iIcon > 0 Then
    If NotExistInImageList(Me.imgLarge, .iIcon) Then
    imgLarge.ListImages.Add , "K" & .iIcon,
    Me.Picture1(1).Picture
    End If
    itm.Icon = "K" & .iIcon
    End If
    End With
    End If
    If ExtractIconIntoPictureUsingFile(sFileName, Me.Picture1(0), False,
    tSmall) Then
    With tSmall
    If .iIcon > 0 Then
    If NotExistInImageList(Me.imgSmall, .iIcon) Then
    imgSmall.ListImages.Add , "K" & .iIcon,
    Me.Picture1(0).Picture
    End If
    itm.SmallIcon = "K" & .iIcon
    End If
    End With
    End If
    sType = Trim$(tLarge.szTypeName)
    sType = UseExtIfBlank(sType, sFileName)
    End Sub

    Private Function UseExtIfBlank(sType As String, sFileName As String) As
    String
    ' 2000/02/01 Return the extension if no type
    Dim sFile As String
    Dim sExt As String
    If sType <> "" Then
    UseExtIfBlank = sType
    Else
    sExt = GetExtensionFromFileName(sFileName, sFile)
    If sExt <> "" Then
    sExt = UCase$(sExt) & " File"
    End If
    UseExtIfBlank = sExt
    End If
    End Function


    --
    Cheers,
    Larry Rebich

    More tips link to:
    http://www.buygold.net/tips

    Please:
    No personal e-mail questions :-)


    "Brad Siemens" <ebspc@sympatico.ca> wrote in message
    news:3b865ddd$1@news.devx.com...
    > I'm attempting to get the icon associated with a file and assign it to a
    > Listitem in an imagelist control. I am using as my guide 'Retrieving an
    > Associated 16x16 Icon Using SHGetFileInfo' from Randy Birch's VBnet. The
    > example works to assign it to a picture box but try as I might, I can't

    seem
    > to get it to associate with a ListItem.
    >
    > I have tried taking the picture and putting in an imagelist associated

    with
    > the Listview control and it reports that it has been added, but when I
    > assign the image to a Listitem nothing appears. No errors.
    >
    > Anyone have any idea how to accomplish this or am I tilting here?
    >
    > TIA
    > Brad
    >
    > Public Function Set_FileIcon(oFile As cFile) As Long
    > On Error GoTo ****
    >
    > Dim hImgSmall As Long
    >
    > 'get the system icon associated with that file
    > hImgSmall& = SHGetFileInfo(oFile.FullPath, 0&, _
    > shinfo, Len(shinfo), _
    > BASIC_SHGFI_FLAGS Or SHGFI_SMALLICON)
    >
    > oFile.Icon = shinfo.iIcon
    >
    > 'draw the associated icon into the picturebox
    > Call ImageList_Draw(hImgSmall&, shinfo.iIcon, _
    > fOpen.Picture3.hDC, 0, 0, ILD_TRANSPARENT)
    >
    > If Not fOpen.Extension_Exists(oFile.Icon) Then
    > fOpen.imlSmall.ListImages.Add , oFile.Icon, fOpen.Picture3.Image
    > End If
    >
    > Exit Function
    > ****:
    > oErrors.LogToErrorFile Err.Number, "mFiles:Get_FileIcon(ByVal Path As
    > String) As Long", Err.Description, Err.HelpFile, Err.HelpContext
    > Err.Number = 0
    > Resume Next
    > End Function
    >
    >




  4. #4
    Klaus H. Probst Guest

    Re: Icon in Imagelist

    Check out the System ImageList sample at www.vbbox.com/codebox.htm


    --
    .. . . . . . . . . . . . . . . . . . . . . .
    Klaus H. Probst, MVP
    http://www.vbbox.com/


    Please post/reply to the newsgroup(s)



    "Brad Siemens" <ebspc@sympatico.ca> wrote in message
    news:3b865ddd$1@news.devx.com...
    > I'm attempting to get the icon associated with a file and assign it to a
    > Listitem in an imagelist control. I am using as my guide 'Retrieving an
    > Associated 16x16 Icon Using SHGetFileInfo' from Randy Birch's VBnet. The
    > example works to assign it to a picture box but try as I might, I can't

    seem
    > to get it to associate with a ListItem.
    >
    > I have tried taking the picture and putting in an imagelist associated

    with
    > the Listview control and it reports that it has been added, but when I
    > assign the image to a Listitem nothing appears. No errors.
    >
    > Anyone have any idea how to accomplish this or am I tilting here?
    >
    > TIA
    > Brad
    >
    > Public Function Set_FileIcon(oFile As cFile) As Long
    > On Error GoTo ****
    >
    > Dim hImgSmall As Long
    >
    > 'get the system icon associated with that file
    > hImgSmall& = SHGetFileInfo(oFile.FullPath, 0&, _
    > shinfo, Len(shinfo), _
    > BASIC_SHGFI_FLAGS Or SHGFI_SMALLICON)
    >
    > oFile.Icon = shinfo.iIcon
    >
    > 'draw the associated icon into the picturebox
    > Call ImageList_Draw(hImgSmall&, shinfo.iIcon, _
    > fOpen.Picture3.hDC, 0, 0, ILD_TRANSPARENT)
    >
    > If Not fOpen.Extension_Exists(oFile.Icon) Then
    > fOpen.imlSmall.ListImages.Add , oFile.Icon, fOpen.Picture3.Image
    > End If
    >
    > Exit Function
    > ****:
    > oErrors.LogToErrorFile Err.Number, "mFiles:Get_FileIcon(ByVal Path As
    > String) As Long", Err.Description, Err.HelpFile, Err.HelpContext
    > Err.Number = 0
    > Resume Next
    > End Function
    >
    >




  5. #5
    Klaus H. Probst Guest

    Re: Icon in Imagelist

    Check out the System ImageList sample at www.vbbox.com/codebox.htm


    --
    .. . . . . . . . . . . . . . . . . . . . . .
    Klaus H. Probst, MVP
    http://www.vbbox.com/


    Please post/reply to the newsgroup(s)



    "Brad Siemens" <ebspc@sympatico.ca> wrote in message
    news:3b865ddd$1@news.devx.com...
    > I'm attempting to get the icon associated with a file and assign it to a
    > Listitem in an imagelist control. I am using as my guide 'Retrieving an
    > Associated 16x16 Icon Using SHGetFileInfo' from Randy Birch's VBnet. The
    > example works to assign it to a picture box but try as I might, I can't

    seem
    > to get it to associate with a ListItem.
    >
    > I have tried taking the picture and putting in an imagelist associated

    with
    > the Listview control and it reports that it has been added, but when I
    > assign the image to a Listitem nothing appears. No errors.
    >
    > Anyone have any idea how to accomplish this or am I tilting here?
    >
    > TIA
    > Brad
    >
    > Public Function Set_FileIcon(oFile As cFile) As Long
    > On Error GoTo ****
    >
    > Dim hImgSmall As Long
    >
    > 'get the system icon associated with that file
    > hImgSmall& = SHGetFileInfo(oFile.FullPath, 0&, _
    > shinfo, Len(shinfo), _
    > BASIC_SHGFI_FLAGS Or SHGFI_SMALLICON)
    >
    > oFile.Icon = shinfo.iIcon
    >
    > 'draw the associated icon into the picturebox
    > Call ImageList_Draw(hImgSmall&, shinfo.iIcon, _
    > fOpen.Picture3.hDC, 0, 0, ILD_TRANSPARENT)
    >
    > If Not fOpen.Extension_Exists(oFile.Icon) Then
    > fOpen.imlSmall.ListImages.Add , oFile.Icon, fOpen.Picture3.Image
    > End If
    >
    > Exit Function
    > ****:
    > oErrors.LogToErrorFile Err.Number, "mFiles:Get_FileIcon(ByVal Path As
    > String) As Long", Err.Description, Err.HelpFile, Err.HelpContext
    > Err.Number = 0
    > Resume Next
    > End Function
    >
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center