delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback



Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi








Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (0)


Function to work with icons in DLL, EXE and ICO filesFormat this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi all versions
Category:
Files Operation
Skill Level:
Scoring:
Last Update:
11/24/2001
Search Keys:
delphi delphi3000 article borland vcl code-snippet ICO EXE DLL extract icon count
Times Scored:
3
Visits:
5333
Uploader: Christian Cristofori
Company: Function2 by C. Cristofori
Reference: N/A
 
Question/Problem/Abstract:
There are a list of solution, but those are what i personally use for that work.
Answer:



You need to include the ShellAPI unit in your uses clausole!

// This returns how many icons are in a file.
Function DLLIconsCount( FileName : String ) : Integer;
Var
  IconaGrande  : HIcon;
  IconaPiccola : HIcon;
Begin
  Result := 0;
  If ( FileExists( FileName ) ) Then Begin
    Result := ExtractIconEx( PChar( FileName ), -1, IconaGrande, IconaPiccola, 0 );
  End;
End;

// This returns if there're icons in a file
Function DLLHasIcons( FileName : String ) : Boolean;
Begin
  Result := ( DLLIconsCount( FileName ) > 0 );
End;

// This returns a TIcon for a given file and index.
Function GetDLLIcon( FileName : String; Index : Integer = 0 ) : TIcon;
Begin
  Result := TIcon.Create;
  Result.Handle := 0;
  If ( DLLHasIcons( FileName ) ) Then Begin
    Try
      If ( Index < 0 ) Then Index := 0;
      If ( Index > DLLIconsCount( FileName ) ) Then Index := DLLIconsCount( FileName );
      Result.Handle := ExtractIcon( 0, PChar( FileName ), Index );
    Finally
    End;
  End;
End;

// This saves an icon from a DLL (EXE or ICO) to a ICO file.
Function ExportDLLIcon( OutputFile, InputFile : String; Index : Integer = 0 ) : Boolean;
Var
  Icona : TIcon;
Begin
  Result := False;
  Icona := GetDLLIcon( InputFile, Index );
  If ( Not( Icona.Handle = 0 ) ) Then
    Try
      Icona.SaveToFile( OutputFile );
    Finally
      If ( FileExists( OutputFile ) ) Then
        Result := True;
    End;
  Icona.Destroy;
End;

// This is like ExportDLLIcon, but it saves a bitmap file.
Function ExportDLLIconAsBitmap( OutputFile, InputFile : String; Index : Integer = 0 ) : Boolean;
Var
  Icona    : TIcon;
  Immagine : TBitmap;
Begin
  Result := False;
  Icona := GetDLLIcon( InputFile, Index );
  Immagine := TBitmap.Create;
  If ( Not( Icona.Handle = 0 ) ) Then
    Try
      Immagine.Assign( Icona );
      Immagine.SaveToFile( OutputFile );
    Finally
      If ( FileExists( OutputFile ) ) Then
        Result := True;
    End;
  Icona.Destroy;
  Immagine.Destroy;
End;





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment













 
Sign up to consume product discounts for Bronze memberships !

read more


   


  Community Ad of
L. Rosenstein
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)