Marco Cantù 1998, Mastering Delphi 4
Project: USEICONS.DPR
Project Structure
USEICONS.DPR
program Useicons;
uses
Forms,
UseIconF in 'UseIconF.pas' {Form1};
{$R *.RES}
begin
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
USEICONF.PAS
unit UseIconF;
interface
uses
SysUtils, Windows, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
LoadButton: TButton;
Edit1: TEdit;
Bevel1: TBevel;
Label1: TLabel;
procedure LoadButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
HInst: THandle;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.LoadButtonClick(Sender: TObject);
var
HIcon: THandle;
begin
HIcon := LoadIcon (HInst, PChar(Edit1.Text));
if HIcon = 0 then
ShowMessage ('Icon not found')
else
Image1.Picture.Icon.Handle := HIcon;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
HInst := LoadLibrary ('Iconsdll.dll');
if HInst = 0 then
begin
LoadButton.Enabled := False;
ShowMessage ('Icons DLL not found');
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FreeLibrary (HInst);
end;
end.
USEICONF.DFM
object Form1: TForm1
Left = 238
Top = 185
Width = 299
Height = 162
Caption = 'Use Icons'
Font.Color = clBlack
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OnCreate = FormCreate
OnDestroy = FormDestroy
PixelsPerInch = 96
TextHeight = 13
object Bevel1: TBevel
Left = 113
Top = 64
Width = 64
Height = 57
end
object Image1: TImage
Left = 121
Top = 72
Width = 48
Height = 41
end
object Label1: TLabel
Left = 16
Top = 28
Width = 53
Height = 13
Caption = 'Icon name:'
end
object LoadButton: TButton
Left = 200
Top = 24
Width = 73
Height = 25
Caption = 'Load'
TabOrder = 0
OnClick = LoadButtonClick
end
object Edit1: TEdit
Left = 81
Top = 24
Width = 105
Height = 21
TabOrder = 1
Text = 'ICON_A'
end
end
Copyright Marco Cantù 1998