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