Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

small icons in files

Posted on 2000-05-14
4
Medium Priority
?
165 Views
Last Modified: 2010-04-04
How can I extract a small icon from a exe using the icon index? I know it can be done without the icon index with something like ShGetFileInfo(...). Or with big icons and the icon index with ExtractIcon(...) but I need little icons! Anybody know how to do this?
0
Comment
Question by:zilog
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 200 total points
ID: 2808465
hi,
here is example of extracting small and large icons using extracticonex()


unit ExtractIconExU;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, FileCtrl, StdCtrls, ShellAPI;

type
  TForm1 = class(TForm)
    DriveComboBox1: TDriveComboBox;
    DirectoryListBox1: TDirectoryListBox;
    FileListBox1: TFileListBox;
    Label1: TLabel;
    ScrollBox1: TScrollBox;
    ScrollBox2: TScrollBox;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Image1: TImage;
    Image2: TImage;
    procedure FileListBox1DblClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  LargeIconsBitmap: TBitmap;  // this holds the icon images
  SmallIconsBitmap: TBitmap;

implementation

{$R *.DFM}

procedure TForm1.FileListBox1DblClick(Sender: TObject);
var
   NumIcons: Integer;         // holds the icon count
   LIcon: HICON;              // holds the handles to extracted icons
   SIcon: HICON;
   LoopCount: Integer;        // a general loop counter
begin
   {determine the number of icons stored in this file}
   NumIcons:=ExtractIconEx(PChar(FileListBox1.FileName), -1, LIcon, SIcon, 0);

   {display this number}
   Label4.Caption:='Total Number of Icons: '+IntToStr(NumIcons);

   {resize the images and clear the canvases of the offscreen bitmaps.
    we add a 1 to the width in case there are no icons. this prevents
    the Height of these objects from being reset to 1.}
   Image1.Width:=NumIcons*40+1;
   Image2.Width:=NumIcons*40+1;
   LargeIconsBitmap.Width:=NumIcons*40+1;
   LargeIconsBitmap.Canvas.FillRect(LargeIconsBitmap.Canvas.ClipRect);
   SmallIconsBitmap.Width:=NumIcons*40+1;
   SmallIconsBitmap.Canvas.FillRect(SmallIconsBitmap.Canvas.ClipRect);

   {extract each large and small icon from the file}
   for LoopCount:=0 to NumIcons-1 do
   begin
      {find the icon in the selected application, if one exists}
      ExtractIconEx(PChar(FileListBox1.FileName), LoopCount, LIcon, SIcon, 1);

      {display the large icon}
      DrawIcon(LargeIconsBitmap.Canvas.Handle, (LoopCount*40)+4, 2, LIcon);

      {draw the small icon to the correct dimensions}
      DrawIconEx(SmallIconsBitmap.Canvas.Handle, (LoopCount*40)+4, 2, SIcon,
                 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
                 0, 0, DI_NORMAL);
   end;

   {assign the offscreen bitmaps to the images for display}
   Image1.Picture.Bitmap.Assign(LargeIconsBitmap);
   Image2.Picture.Bitmap.Assign(SmallIconsBitmap);
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
   {create the offscreen bitmaps to hold the images of the icons.}
   LargeIconsBitmap:=TBitmap.Create;
   LargeIconsBitmap.Height:=53;
   LargeIconsBitmap.Width:=40;

   SmallIconsBitmap:=TBitmap.Create;
   SmallIconsBitmap.Height:=53;
   SmallIconsBitmap.Width:=40;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
   {free the offscreen bitmaps}
   LargeIconsBitmap.Free;
   SmallIconsBitmap.Free;
end;

end.




Regards Barry

0
 
LVL 17

Expert Comment

by:inthe
ID: 2808468
oops forgot the "form as text" view

object Form1: TForm1
  Left = 321
  Top = 159
  BorderStyle = bsDialog
  Caption = 'ExtractIconEx Example'
  ClientHeight = 354
  ClientWidth = 314
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  OnCreate = FormCreate
  OnDestroy = FormDestroy
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 0
    Top = 0
    Width = 314
    Height = 26
    Align = alTop
    Caption =
      'Double click on a file in the list box. If it is an application,' +
      ' its icons will be displayed below.'
    WordWrap = True
  end
  object Label2: TLabel
    Left = 8
    Top = 168
    Width = 56
    Height = 13
    Caption = 'Large Icons'
  end
  object Label3: TLabel
    Left = 8
    Top = 264
    Width = 54
    Height = 13
    Caption = 'Small Icons'
  end
  object Label4: TLabel
    Left = 196
    Top = 168
    Width = 108
    Height = 13
    Alignment = taRightJustify
    Caption = 'Total Number of Icons:'
  end
  object DriveComboBox1: TDriveComboBox
    Left = 8
    Top = 40
    Width = 145
    Height = 19
    DirList = DirectoryListBox1
    TabOrder = 0
  end
  object DirectoryListBox1: TDirectoryListBox
    Left = 8
    Top = 64
    Width = 145
    Height = 97
    FileList = FileListBox1
    ItemHeight = 16
    TabOrder = 1
  end
  object FileListBox1: TFileListBox
    Left = 160
    Top = 40
    Width = 145
    Height = 121
    ItemHeight = 16
    ShowGlyphs = True
    TabOrder = 2
    OnDblClick = FileListBox1DblClick
  end
  object ScrollBox1: TScrollBox
    Left = 8
    Top = 184
    Width = 297
    Height = 73
    TabOrder = 3
    object Image1: TImage
      Left = 0
      Top = 0
      Width = 105
      Height = 53
    end
  end
  object ScrollBox2: TScrollBox
    Left = 8
    Top = 280
    Width = 297
    Height = 65
    TabOrder = 4
    object Image2: TImage
      Left = 0
      Top = 0
      Width = 105
      Height = 45
    end
  end
end
0
 
LVL 3

Expert Comment

by:bryan7
ID: 2809066
listenning
0
 

Author Comment

by:zilog
ID: 2810502
That's exactly what I wanted Inthe. And it works in my old version of Delphi 3 too.
Thanks for answering my question so quickly.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question