Results 1 to 3 of 3

Thread: Extract Icon Of Folder Or Files

  1. #1

    Thread Starter
    Lively Member SNIPER.PS's Avatar
    Join Date
    Dec 2009
    Posts
    96

    Arrow Extract Icon Of Folder Or Files

    Hello

    When I Extract Icon Of Folder Or Files The Icon Appear I PictureBox with this code

    PHP Code:
    'Create a new project, and add this code to Form1
    Const DI_MASK = &H1
    Const DI_IMAGE = &H2
    Const DI_NORMAL = DI_MASK Or DI_IMAGE
    Private Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias "ExtractAssociatedIconA" (ByVal hInst As Long, ByVal lpIconPath As String, lpiIcon As Long) As Long
    Private Declare Function DrawIconEx Lib "user32" (ByVal hdc As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
    Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long

    Private Sub Command1_Click()
    Dim mIcon As Long
    '
    Extract the associated icon
    mIcon 
    ExtractAssociatedIcon(App.hInstance"C:\New Folder\", 2)
    'Draw the icon on the form
    DrawIconEx Picture1.hdc, 0, 0, mIcon, 0, 0, 0, 0, DI_NORMAL
    'remove the icon from the memory
    DestroyIcon mIcon

    End Sub 
    How Can I Save The Picture.. Help Me Please

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Extract Icon Of Folder Or Files

    Code:
    SavePicture Picture1.Picture, "c:\myIcon.bmp"

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Extract Icon Of Folder Or Files

    Hack's solution works well but will save the icon as bitmap and any transparency will be lost. If this is not an issue, then all is good. However, you can look at post #2 on this thread. I supplied code that can be added to a form, class or module and will take an Icon handle and save it to file.

    Keep this in mind too. Just because you can load an icon, doesn't mean you can use it in VB's picture/icon properties. VB does not support 32 bit icons (true color + alpha channel).

    Edited: I've taken this topic a bit further and included the linked sample code plus some other stuff into a new CodeBank thread. You may want to visit there.
    Last edited by LaVolpe; Jan 7th, 2011 at 08:31 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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