Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

[2982] File Extensions: Finding the default Icon

Last post 05-22-2007 6:53 PM by Anishsane. 12 replies.
Page 1 of 1 (13 items)
Sort Posts: Previous Next
  • 01-01-1999 12:00 AM

    [2982] File Extensions: Finding the default Icon

    This thread is for discussions of File Extensions: Finding the default Icon.

    • Post Points: 45
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 01-02-2003 8:49 PM In reply to

    Small Icons

    Fantastic tutorial. Especially as I've just started a project, this evening, that'll have file lists and icons - solved quite a head scratcher for me.

    But I was wandering, is it a simple matter to use the small versions of the icons, as you get in explorer? If so, could someone tell me where to look for how

    Tom.
    • Post Points: 0
  • 01-04-2003 1:27 PM In reply to

    • couling
    • Top 50 Contributor
    • Joined on 05-13-2002
    • United Kingdom
    • Guru
    • Points 2,440

    Gotta go ...Ex

    Sorry this took a while
    Ok, Small Icons:
    These will be a little more complex, you will need to use two more windows APIs:

    ExtractIconEx (instead of ExtractIconEx)
    DrawIconEx (instead of DrawIcon)

    These functions do basically the same thing, but they are capable of much more. ExtractIconEx can extract any number of Icons into two arrays (although in the example below I’ve only used two long variables “lngSmall” and “lngLarge”).  DrawIconEx will allow you to draw the small icon as a 16 X 16 image instead of 32 X 32.  This is just a small example of how to use the two functions, hopefully you can see how to alter the origional code.  You will need:

    two picture boxes (to receve the images)
    an icon (in the code Ive used the path "C:\1.ico")
    A command button (the subroutine is "command1_CLick()")

    So for some code:

    Code:
    Private Declare Function ExtractIconEx Lib "shell32.dll" Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal nIconIndex As Long, phiconLarge As Long, phiconSmall As Long, ByVal nIcons As Long) As Long
    Private Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As Long) As Long
    Private Declare Function DrawIconEx Lib "user32.dll" (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 Const DI_NORMAL = &H3 'Draw both the image mask in image data
    Private Const DI_DEFAULTSIZE = &H8 'Draw the icon at 32 X 32

    Private Sub Command1_Click()
       Dim Retval As Long, lngLarge As Long, lngSmall As Long, hbrush As Long
       
       '                                  \/firstIcon            \/Number of icons
       Retval = ExtractIconEx("C:\1.ico", 0, lngLarge, lngSmall, 1)
       
       Retval = DrawIconEx(Picture1.hDC, 0, 0, lngLarge, 0, 0, 0, 0, DI_NORMAL Or DI_DEFAULTSIZE)
       'note: DI_DEFAULTSIZE tells windows to ignore the two parameters after "lngLarge".
           
       Retval = DrawIconEx(Picture2.hDC, 0, 0, lngSmall, 16, 16, 0, 0, DI_NORMAL)
       '"16,16 tells windows to draw the Icon 16 X 16 pixals
       
       '                                  left   top   Icon   width  height  for drawing animated cursors      brush type     Flags
       'Retval = DrawIconEx(Picture2.hDC,   0,    0,   lngSmall,  16,    16,              0,                           0,      DI_NORMAL)
       
       Retval = DestroyIcon(lngLarge) 'As in the article
       Retval = DestroyIcon(lngSmall)
    End Sub


    To get ExatractIconEx to retrieve more than one Icon, replace lngLarge and lngSmall with arrays and set the last parameter “nIcons” to the number of icons to extract.

    If this isn't clear just say so.
    • Post Points: 0
  • 01-18-2003 1:19 PM In reply to

    • FXander
    • Not Ranked
    • Joined on 01-18-2003
    • New Member
    • Points 5

    Persistent?

    Hi, this is great code! I just have one question...

    When form minimize or is hidden behind another one, the drawn icon just dissapear, how can I make it persistant?? how can I convert it to a Picture Object I could manipulate to assign it to any other control???

    • Post Points: 0
  • 01-19-2003 10:01 AM In reply to

    • couling
    • Top 50 Contributor
    • Joined on 05-13-2002
    • United Kingdom
    • Guru
    • Points 2,440

    ...AutoRedraw = True

    In the properties of the picturebox, set "AutoRedraw" to "True"

    If you want to draw to other objects, you can either
    1.    Code:
    “GetDefaultIcon Text1.Text, Picture1.hDC”
     When you use this line to call the function, simply replace picture1 with the name of the object.  This will only work if the object has a “hDC” property at runtime (when the program is run)

    2.    If your object has a “Picture” or “Image” property then you could use:
    Code:
    “GetDefaultIcon Text1.Text, Picture1.hDC”
    Object.Picture = Picture1.Image

    Or
    Code:
    “GetDefaultIcon Text1.Text, Picture1.hDC”
    Object.Image = Picture1.Image


    Hope this helps
    • Post Points: 0
  • 02-18-2003 8:55 AM In reply to

    • durgesh
    • Not Ranked
    • Joined on 12-22-2001
    • New Member
    • Points 30

    Very Nice Listing

    Very Nice Very Nice Very Nice Very Nice Very Nice Very Nice !!!
    Really Very Nice
    • Post Points: 0
  • 02-20-2003 9:01 PM In reply to

    • couling
    • Top 50 Contributor
    • Joined on 05-13-2002
    • United Kingdom
    • Guru
    • Points 2,440

    Thanks a lot

    Thanks for your (repeatedly) very kind words
    • Post Points: 0
  • 09-13-2003 7:10 PM In reply to

    • jab
    • Not Ranked
    • Joined on 09-13-2003
    • New Member
    • Points 10
    Lovely coding couling! Its helped me alot.

    I'm not too hot with API work though and have had trouble incorporating your two lots of code.  I'm ultimately trying to display the associated file icons from a directory of scanned files from a database on a Listview (like Explorer), using a 16x16 picture box. 32x32 is no problem (in theoy) but I'm unable to get my head round the 16x16 bit.

    Any help VERY much appreciated.
    • Post Points: 0
  • 09-13-2003 8:13 PM In reply to

    • couling
    • Top 50 Contributor
    • Joined on 05-13-2002
    • United Kingdom
    • Guru
    • Points 2,440
    Looks like my reply is too large to fit in one post so I've put it here.

    Hope this helps
    • Post Points: 0
  • 09-18-2003 4:13 PM In reply to

    • jab
    • Not Ranked
    • Joined on 09-13-2003
    • New Member
    • Points 10
    Absolutely brilliant! Works a treat.

    THANKS VERY MUCH!!!
    • Post Points: 0
  • 06-02-2005 9:52 PM In reply to

    • Tochukwu
    • Not Ranked
    • Joined on 05-11-2005
    • New Member
    • Points 5

    INTERESTING

    THAT WAS A NICE JOB.

    I AM AN UNDERGRADUATE STUDYING COMPUTER PRORAMMING. i WILL NEED MORE EXPLANATION ON THIS TOPIC.

    tOCHUKWU.
    • Post Points: 0
  • 07-16-2005 5:46 PM In reply to

    About lessons and codes

    I'll never be thankful enough to have decided to join Developer Fusion. It's real fun to have what's needed to start with programming language. I am really amazed of the progresses i have done in two weeks in learning progamming with visual basic

    Thanks a lot for the help and the good job you're doing

    Yves
    • Post Points: 0
  • 05-22-2007 6:53 PM In reply to

    • Anishsane
    • Not Ranked
    • Joined on 05-22-2007
    • India
    • New Member
    • Points 5

    Re: [2982] File Extensions: Finding the default Icon

    does any one want to extract image used for icon?
    the icon may be in an exe file or dll file.
    this is a veryyyyyyyy long way, and there are ready softwares available for it.

    but it is discovered by me, so posting Smiley Face [:)]

    in folder options, create a dummy file extension
    click advanced,
    change the icon of that file extension to desired icon; from dll or exe file.

    open google talk (sounds funny naa)
    now create a file with that extension
    using file transfer option, send that file to someone
    it is not needed that actual transfer shd take place, u only need to initiate the transfer & then u can abort the transfer.
    now go to
    %userprofile%\Local Settings\Temp\Google Talk\File Extensions
    the icon file is seen there as a png image
    open it with mspaint or similar software & save it as 256 color bitmap
    change its extension to .ico from .bmp
    & u r done






















    • Post Points: 5
Page 1 of 1 (13 items)