Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
Function to work with icons in DLL, EXE and ICO files Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
02-Sep-03
Category
Files Operation
Language
Delphi 2.x
Views
201
User Rating
9
# Votes
1
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Christian Cristofori

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! 
1   
2   // This returns how many icons are in a file.
3   
4   function DLLIconsCount(FileName: string): Integer;
5   var
6     IconaGrande: HIcon;
7     IconaPiccola: HIcon;
8   begin
9     Result := 0;
10    if (FileExists(FileName)) then
11    begin
12      Result := ExtractIconEx(PChar(FileName), -1, IconaGrande, IconaPiccola, 0);
13    end;
14  end;
15  
16  // This returns if there're icons in a file
17  
18  function DLLHasIcons(FileName: string): Boolean;
19  begin
20    Result := (DLLIconsCount(FileName) > 0);
21  end;
22  
23  // This returns a TIcon for a given file and index.
24  
25  function GetDLLIcon(FileName: string; Index: Integer = 0): TIcon;
26  begin
27    Result := TIcon.Create;
28    Result.Handle := 0;
29    if (DLLHasIcons(FileName)) then
30    begin
31      try
32        if (Index < 0) then
33          Index := 0;
34        if (Index > DLLIconsCount(FileName)) then
35          Index := DLLIconsCount(FileName);
36        Result.Handle := ExtractIcon(0, PChar(FileName), Index);
37      finally
38      end;
39    end;
40  end;
41  
42  // This saves an icon from a DLL (EXE or ICO) to a ICO file.
43  
44  function ExportDLLIcon(OutputFile, InputFile: string; Index: Integer = 0): Boolean;
45  var
46    Icona: TIcon;
47  begin
48    Result := False;
49    Icona := GetDLLIcon(InputFile, Index);
50    if (not (Icona.Handle = 0)) then
51    try
52      Icona.SaveToFile(OutputFile);
53    finally
54      if (FileExists(OutputFile)) then
55        Result := True;
56    end;
57    Icona.Destroy;
58  end;
59  
60  // This is like ExportDLLIcon, but it saves a bitmap file.
61  
62  function ExportDLLIconAsBitmap(OutputFile, InputFile: string; Index: Integer = 0):
63    Boolean;
64  var
65    Icona: TIcon;
66    Immagine: TBitmap;
67  begin
68    Result := False;
69    Icona := GetDLLIcon(InputFile, Index);
70    Immagine := TBitmap.Create;
71    if (not (Icona.Handle = 0)) then
72    try
73      Immagine.Assign(Icona);
74      Immagine.SaveToFile(OutputFile);
75    finally
76      if (FileExists(OutputFile)) then
77        Result := True;
78    end;
79    Icona.Destroy;
80    Immagine.Destroy;
81  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC