Results 1 to 4 of 4

Thread: Easy?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    Would it be easy to extract an icon from a file, then add it to an ImageList for use by TreeView control?

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Yep, it is, just download a control from vbaccelerator.com called Icon Extractor and extract the icon, then you could put it in any Imagelist like you always did.
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    Note to self: be more specific in VB forums.

    I mean during execution of my application.

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Ok, you need to have a treeview, a imagelist and a picturebox (hidden with autoredraw on)
    Code:
    'In a module
    Declare Function ExtractIconEx Lib "shell32" Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal nIconIndex As Long, phIconLarge As Long, phIconSmall As Long, ByVal nIcons As Long) As Long
    Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hicon As Long) As Long
    
    Function GetIconsFromFile(Filename$)
        Dim hIcons()
        ReDim hIcons(ExtractIconEx(Filename, -1, ByVal 0&, ByVal 0&, 0))
        If UBound(hIcons) = 0 Then Exit Function Else ReDim Preserve hIcons(UBound(hIcons) - 1)
        ExtractIconEx Filename, 0, hIcons(0), ByVal 0&, 10
        GetIconsFromFile = hIcons
    End Function
    
    Function GetIconFromFile&(Filename$, Optional index&)
        ExtractIconEx Filename, index, GetIconsFromFile, ByVal 0&, 10
    End Function
    
    
    'In code
    DrawIcon picture1.hdc, 0, 0, GetIconFromFile(YourFilepath)
    ImageList1.ListImages.Add , "YourIcon", picture1.Picture
    TreeView1.Nodes.Add , , , "Caption", "YourIcon"
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width