Delphi extracts all icons in the executable file

Source: Internet
Author: User

Add the timage component, topendialog component, and tbutton component to the form. The timage component acts as a display file.
The topendialog component and the tbutton component are used to activate the dialog box prompting users to select GIF animation.

First, add the shellapi in the uses section of the form, and then add the button Response Code as follows:

Procedure tform1.button1click (Sender: tobject );
VaR
I: integer;
Largeicon, smallicon: hicon;
Num: integer;
Begin
If opendialog1.execute then
Begin
Self. image1.canvas. Refresh;
Num: = extracticonex (pchar (opendialog1.filename ),
-1, // set to-1 to return the number of specified files
Largeicon,
Smallicon,
1 );
For I: = 0 to num-1 do // in this way, the last icon is the program icon.
Begin
Extracticonex (pchar (opendialog1.filename), I, largeicon, smallicon, 1 );
Drawicon (image1.canvas. Handle, (I Div 4) * 40, (I mod 4) * 40, large );
End;
End;
End;

When you select an executable file during the program running, the program first uses self. image1.canvas.
The refresh statement clears the display content on the timage component, and then specifies the display content by specifying the 2nd parameters of the extracticonex function.
-1 to obtain the number of objects in the executable file. After obtaining the number, use extracticonex (PCH
AR (self. opendialog1.filename), I, large, small, 1) Statement to put the large and small icons in the executable file
Stored in the large and small variables respectively. Finally, draw an icon on the timage component using the drawicon function.

The code of the entire unit program is as follows:

Unit unit1;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, extctrls, stdctrls, shellapi, grids;

Type
Tform1 = Class (tform)
Button1: tbutton;
Image1: timage;
Opendialog1: topendialog;
Procedure button1click (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;

VaR
Form1: tform1;

Implementation

{$ R *. DFM}

Procedure tform1.button1click (Sender: tobject );
VaR
I: integer;
Largeicon, smallicon: hicon;
Num: integer;
Begin
If opendialog1.execute then
Begin
Self. image1.canvas. Refresh;
Num: = extracticonex (pchar (opendialog1.filename ),
-1, // set to-1 to return the number of specified files
Largeicon,
Smallicon,
1 );
For I: = 0 to num-1 do // in this way, the last icon is the program icon.
Begin
Extracticonex (pchar (opendialog1.filename), I, largeicon, smallicon, 1 );
Drawicon (image1.canvas. Handle, (I Div 4) * 40, (I mod 4) * 40, largeicon );
End;
End;
End;

End.

 

Delphi extracts all icons in the executable file

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.