1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
| unit IconLoader_MainForm;
interface
uses
(*Winapi.*)Windows, (*Winapi.*)
(*System.*)SysUtils, (*System.*)Variants, (*System.*)Classes,
(*Vcl.*)Graphics, (*Vcl.*)Controls, (*Vcl.*)Forms,
(*Vcl.*)Dialogs, (*Vcl.*)StdCtrls, Vcl.ExtCtrls;
type
TIconLoaderMainForm = class(TForm)
btnLoad: TButton;
OpenDialogIcon: TOpenDialog;
ImageDefault: TImage;
ScrollBoxSubIcons: TScrollBox;
lblImageDefaultResolution: TLabel;
procedure btnLoadClick(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
IconLoaderMainForm: TIconLoaderMainForm;
implementation
uses
(*System.*)Math,
(*System.Generics.Collections, *)(*System.*)Contnrs;
type
TIconMulti = class(TIcon)
private
FIcons: TObjectList(*<TIcon>*);
function GetIconCount(): Integer;
function GetIcon(Index: Integer): TIcon;
public
constructor Create(); override;
destructor Destroy(); override;
procedure LoadFromStream(Stream: TStream); override;
property IconCount: Integer read GetIconCount;
property Icons[Index: Integer]: TIcon read GetIcon;
end;
{$R *.dfm}
procedure TIconLoaderMainForm.btnLoadClick(Sender: TObject);
var
LIcon: TIconMulti;
LSubIcon: TIcon;
I, Y: Integer;
PanelSub: TPanel;
LabelSub: TLabel;
ImageSub: TImage;
DefaultRes: string;
begin
ImageDefault.Picture.Bitmap.Assign(nil);
for I := ScrollBoxSubIcons.ControlCount - 1 downto 0 do
ScrollBoxSubIcons.Controls[I].Free();
// OpenDialogIcon.FileName := 'C:\Program Files (x86)\Embarcadero\Studio\17.0\Images\Default\Default.ico';
// OpenDialogIcon.FileName := 'C:\Program Files (x86)\Embarcadero\Studio\17.0\bin\delphi_PROJECTICON.ico';
if OpenDialogIcon.Execute then
begin
LIcon := TIconMulti.Create();
try
DefaultRes := Format('%d x %d', [LIcon.Width, LIcon.Height]);
LIcon.LoadFromFile(OpenDialogIcon.FileName);
ImageDefault.Width := LIcon.Width;
ImageDefault.Height := LIcon.Height;
ImageDefault.Picture.Bitmap.Assign(LIcon);
lblImageDefaultResolution.Caption := Format('%d x %d (Expected: %s)', [LIcon.Width, LIcon.Height, DefaultRes]);
Y := 0;
for I := 0 to LIcon.IconCount - 1 do
begin
LSubIcon := LIcon.Icons[I];
PanelSub := TPanel.Create(Self);
LabelSub := TLabel.Create(Self);
ImageSub := TImage.Create(Self);
ImageSub.Width := LSubIcon.Width;
ImageSub.Height := LSubIcon.Height;
ImageSub.Picture.Bitmap.Assign(LSubIcon);
LabelSub.Caption := Format('%d x %d', [LSubIcon.Width, LSubIcon.Height]);
PanelSub.Parent := ScrollBoxSubIcons;
LabelSub.Parent := PanelSub;
LabelSub.Align := alTop;
ImageSub.Parent := PanelSub;
ImageSub.Align := alClient;
PanelSub.ClientHeight := LSubIcon.Height + LabelSub.Height + 8;
PanelSub.ClientWidth := Max(LSubIcon.Width, LabelSub.Canvas.TextWidth(LabelSub.Caption)) + 8;
PanelSub.Left := 4;
PanelSub.Top := Y;
Inc(Y, PanelSub.Height);
end;
finally
LIcon.Free();
end;
end;
end;
{ TIconMulti }
constructor TIconMulti.Create();
begin
inherited Create();
FIcons := TObjectList(*<TIcon>*).Create(True);
end;
destructor TIconMulti.Destroy();
begin
FreeAndNil(FIcons);
inherited Destroy();
end;
function TIconMulti.GetIcon(Index: Integer): TIcon;
begin
Result := FIcons[Index] as TIcon;
end;
function TIconMulti.GetIconCount(): Integer;
begin
Result := FIcons.Count;
end;
procedure TIconMulti.LoadFromStream(Stream: TStream);
type
PIconRecArray = ^TIconRecArray;
TIconRecArray = array[0..300] of TIconRec;
var
CI: TCursorOrIcon;
I: Integer;
HeaderLen: Integer;
ListIcon: PIconRecArray;
SubIcon: TIcon;
begin
FIcons.Clear();
inherited LoadFromStream(Stream);
Stream.Seek(0, soBeginning); // ou soFromBeginning en D6
Stream.ReadBuffer(CI, SizeOf(CI));
if CI.wType = RC3_ICON then
begin
HeaderLen := SizeOf(TIconRec) * CI.Count;
ListIcon := AllocMem(HeaderLen);
try
Stream.Read(ListIcon^, HeaderLen);
for I := 0 to CI.Count - 1 do
begin
SubIcon := TIcon.Create();
try
SubIcon.Width := ListIcon^[I].Width;
SubIcon.Height := ListIcon^[I].Height;
Stream.Seek(0, soBeginning); // ou soFromBeginning en D6
SubIcon.LoadFromStream(Stream);
FIcons.Add(SubIcon);
except
SubIcon.Free();
raise;
end;
end;
finally
FreeMem(ListIcon, HeaderLen);
end;
end;
end;
end. |