Delphi implementation to extract all the icons inside the executable file

Source: Internet
Author: User
Tags response code

This example implements the ability to extract all the icons from the user's chosen executable file (the suffix name exe) and to display it on the form.

Add Timage components, Topendialog components, and TButton components to the form, Timage Components act as containers for icons within the display file, and Topendialog components and TButton components are used to activate the dialog box that prompts the user to select an animated GIF. The form after you add the component is shown in Figure 1.

Figure 1 form after adding a component

First add Shellapi to the uses section of the form, and then add the button response code as follows:

Procedure Tfrmmain.btnopenclick (Sender:tobject);

Var

I:integer;

Large, Small:hicon;

Nicons:integer;

Begin

If Opendialog1.execute Then

Begin

Self. Image1.Canvas.Refresh;

Nicons:=extracticonex (Pchar (Opendialog1.filename),-1, Large, Small, 1);

For i:=0 to NIcons-1 do

Begin

Extracticonex (Pchar) (self. Opendialog1.filename), I, Large, Small, 1);

DrawIcon (self. Image1.Canvas.Handle, (i div 4) *40, (i mod 4) *40,large);

End

End

End

When a user selects an executable file while the program is running, the program first passes the self. The Image1.canvas. Refresh statement clears the display on the Timage component and then gets the number of icons in the executable by specifying the 2nd parameter of the Extracticonex function as-one. After the number is obtained, the Extracticonex (Pchar (self) In a loop is passed. Opendialog1.filename), I, Large, Small, 1) statements store large and small icons in the executable file in Large and Small variables respectively. Finally, the DrawIcon function is used to draw an icon on the Timage component.

The program code is as follows:

Unit Unit1;

Interface

Uses

Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,

Dialogs, Stdctrls, Shellapi, Grids, Extctrls;

Type

Tfrmmain = Class (Tform)

Btnopen:tbutton;

Opendialog1:topendialog;

Image1:timage;

Procedure Btnopenclick (Sender:tobject);

Private

{Private declarations}

Public

{Public declarations}

End

Var

Frmmain:tfrmmain;

Implementation

{$R *.DFM}

Procedure Tfrmmain.btnopenclick (Sender:tobject);

Var

I:integer;

Large, Small:hicon;

Nicons:integer;

Begin

If Opendialog1.execute Then

Begin

Self. Image1.Canvas.Refresh;

Nicons:=extracticonex (Pchar (Opendialog1.filename),-1, Large, Small, 1);

For i:=0 to NIcons-1 do

Begin

Extracticonex (Pchar) (self. Opendialog1.filename), I, Large, Small, 1);

DrawIcon (self. Image1.Canvas.Handle, (i div 4) *40, (i mod 4) *40,large);

End

End

End

End.

Save the file, and then press F9 to run the program, the initial picture of the program running as shown in Figure 2.

Click the Open button to pop up a dialog box that prompts the user to select an executable file. Once confirmed, displays the icon stored in the selected executable on the Timge component of the form, as shown in Figure 3.

Figure 2 Initial screen of program operation

Figure 3 Program Run results

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.