We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 48,605 times

Contents

Related Categories

File Extensions: Finding the default Icon - The Contingency

couling

The Contingency

In case we can’t find the default icon we need to display the Windows icon. Here’s how:

No_Icon:
    'No icon could be found so we use the normal windows icon
    'This icon is held in shell32.dll in the system directory, Icon 0

    strDefaultIcon = Space(260)
    lngStringLength = GetSystemDirectory(strDefaultIcon, 260)
    strDefaultIcon = Left(strDefaultIcon, lngStringLength) & "SHELL32.DLL"
    lngIconNumber = 0
    GoTo Draw_Icon
    End Sub

The windows icon will be held in the file “SHELL32.DLL” which is in the system folder. So we get the system directory and use that (along with “SHELL32.DLL”) for the file name, then go back to “Draw_Icon”.

At this point I am just going to add an extra piece of code that will handle EXEs. This is because EXEs have no default icon but it’s probably not best to just show the windows icon. So lets use the icon that windows normally uses for EXEs:

Add this near the begging beneath “TempFileName = Right...” and above “lngError = RegOpenKey...”

    If LCase(TempFileName) = ".exe" Then
      strDefaultIcon = Space(260)
      lngStringLength = GetSystemDirectory(strDefaultIcon, 260)
      strDefaultIcon = Left(strDefaultIcon, lngStringLength) & "SHELL32.DLL"
      lngIconNumber = 2
      GoTo Draw_Icon
    End If

This code is just the same as for getting the windows icon, except we now want icon 2 instead of 0.

Just graduated from the University of Birmingham. Computer Science and Artifical Intelligence 2.2 Languages: Java c++ PHP Prolog VB6

Comments

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

    Posted by Anishsane on 22 May 2007

    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 dis...

  • About lessons and codes

    Posted by PATHFINDER on 16 Jul 2005

    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 ...

  • INTERESTING

    Posted by Tochukwu on 02 Jun 2005

    THAT WAS A NICE JOB.

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

    tOCHUKWU.

  • Posted by jab on 18 Sep 2003

    Absolutely brilliant! Works a treat.

    THANKS VERY MUCH!!!

  • Posted by couling on 13 Sep 2003

    Looks like my reply is too large to fit in one post so I've put it [url="http://mysite.freeserve.com/visualbasic/16.htm"]here[/url].

    Hope this helps :cool: