Use builtin dir and group images which look better and also dont depend on a hard-coded (and undocumented?) icon index from shell32.dll.

This commit is contained in:
Martijn Laan 2021-04-08 15:11:59 +02:00
parent 6da2978a70
commit 8a56729ce6
No known key found for this signature in database
GPG Key ID: 9F8C8C5DDA579626
4 changed files with 17 additions and 72 deletions

View File

@ -41,6 +41,7 @@ type
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure InitializeFromResource(const hInstance: HINST; const ResourceName: PChar; const AWidth, AHeight: Integer; const BkColor: TColor);
published
property Align;
property Anchors;
@ -81,6 +82,18 @@ begin
RegisterComponents('JR', [TBitmapImage]);
end;
procedure TBitmapImage.InitializeFromResource(const hInstance: HINST; const ResourceName: PChar; const AWidth, AHeight: Integer; const BkColor: TColor);
begin
{ Set sizes (overrides any scaling) }
Width := AWidth;
Height := AHeight;
{ Load bitmap }
Bitmap.Handle := LoadBitmap(hInstance, ResourceName);
ReplaceColor := RGB(255, 0, 255);
ReplaceWithColor := BkColor;
end;
constructor TBitmapImage.Create(AOwner: TComponent);
begin
inherited Create(AOwner);

Binary file not shown.

View File

@ -80,9 +80,7 @@ begin
OKButton.Caption := SetupMessages[msgButtonOK];
CancelButton.Caption := SetupMessages[msgButtonCancel];
DiskBitmapImage.Bitmap.Handle := LoadBitmap(HInstance, 'DISKIMAGE'); {don't localize};
DiskBitmapImage.ReplaceColor := RGB(255, 0, 255);
DiskBitmapImage.ReplaceWithColor := Color;
DiskBitmapImage.InitializeFromResource(HInstance, 'DISKIMAGE', 48, 48, Color); {don't localize}
TryEnableAutoCompleteFileSystem(PathEdit.Handle);

View File

@ -731,71 +731,6 @@ constructor TWizardForm.Create(AOwner: TComponent);
using the FormCreate event, because if an exception is raised in FormCreate
it's not propagated out. }
procedure LoadSelectDirAndGroupImages;
procedure IconToBitmapImage(const AIcon: HICON; const Ctl: TBitmapImage; const BkColor: TColor);
begin
if AIcon <> 0 then begin
try
with Ctl.Bitmap do begin
Width := 32;
Height := 32;
Canvas.Brush.Color := BkColor;
Canvas.FillRect(Rect(0, 0, 32, 32));
DrawIconEx(Canvas.Handle, 0, 0, AIcon, 32, 32, 0, 0, DI_NORMAL);
end;
finally
DestroyIcon(AIcon);
end;
end;
end;
var
FileInfo: TSHFileInfo;
Path: String;
begin
{ Set sizes (overrides any scaling) }
SelectDirBitmapImage.Width := 32;
SelectDirBitmapImage.Height := 32;
SelectGroupBitmapImage.Width := 32;
SelectGroupBitmapImage.Height := 32;
try
{ We have to extract the icons ourself using ExtractIcon because the
icons SHGetFileInfo returns differ in size depending on whether
"Use large icons" is turned on, and we don't want that.
Note: We *could* avoid SHGetFileInfo altogether and pass 'shell32.dll'
and a hard-coded index directly to ExtractIcon, but I'm worried that
might not work in a future Windows version. }
if (SHGetFileInfo('c:\directory', FILE_ATTRIBUTE_DIRECTORY, FileInfo,
SizeOf(FileInfo), SHGFI_USEFILEATTRIBUTES or SHGFI_ICONLOCATION) <> 0) and
(FileInfo.szDisplayName[0] <> #0) then
IconToBitmapImage(ExtractIcon(HInstance, FileInfo.szDisplayName,
FileInfo.iIcon), SelectDirBitmapImage, SelectDirPage.Color);
if WindowsVersionAtLeast(6, 0) then begin
{ On Windows Vista and 7, use the "Taskbar and Start Menu Properties"
icon as there is no longer a separate icon for Start Menu folders }
IconToBitmapImage(ExtractIcon(HInstance,
PChar(AddBackslash(WinSystemDir) + 'shell32.dll'), 39),
SelectGroupBitmapImage, SelectProgramGroupPage.Color);
end
else begin
Path := GetShellFolder(False, sfPrograms, False);
if Path = '' then
Path := GetShellFolder(True, sfPrograms, False);
if Path <> '' then begin
if (SHGetFileInfo(PChar(Path), 0, FileInfo, SizeOf(FileInfo),
SHGFI_ICONLOCATION) <> 0) and (FileInfo.szDisplayName[0] <> #0) then
IconToBitmapImage(ExtractIcon(HInstance, FileInfo.szDisplayName,
FileInfo.iIcon), SelectGroupBitmapImage, SelectProgramGroupPage.Color);
end;
end;
except
{ ignore any exceptions }
end;
end;
function SelectBestImage(WizardImages: TList; TargetWidth, TargetHeight: Integer): TBitmap;
var
TargetArea, Difference, SmallestDifference, I: Integer;
@ -936,10 +871,9 @@ begin
WizardBitmapImage2.Stretch := (shWizardImageStretch in SetupHeader.Options);
WizardSmallBitmapImage.Bitmap := SelectBestImage(WizardSmallImages, WizardSmallBitmapImage.Width, WizardSmallBitmapImage.Height);
WizardSmallBitmapImage.Stretch := (shWizardImageStretch in SetupHeader.Options);
PreparingErrorBitmapImage.Bitmap.Handle := LoadBitmap(HInstance, 'STOPIMAGE');
PreparingErrorBitmapImage.ReplaceColor := RGB(255, 0, 255);
PreparingErrorBitmapImage.ReplaceWithColor := PreparingPage.Color;
LoadSelectDirAndGroupImages;
SelectDirBitmapImage.InitializeFromResource(HInstance, 'DIRIMAGE', 32, 32, SelectDirPage.Color); {don't localize}
SelectGroupBitmapImage.InitializeFromResource(HInstance, 'GROUPIMAGE', 32, 32, SelectProgramGroupPage.Color); {don't localize}
PreparingErrorBitmapImage.InitializeFromResource(HInstance, 'STOPIMAGE', 16, 16, PreparingPage.Color); {don't localize}
{ Initialize wpWelcome page }
RegisterExistingPage(wpWelcome, WelcomePage, nil, '', '');