I'm trying to have an image on a custom page I can get the custom page to show or the image on a predefined page but not on the custom page.
Problem I think is with Parent := CustomPage.ID;
.
Parent := WizardForm.SelectTasksPage;
works though.
How to do this properly?
procedure ImageOnClick(Sender: TObject);
var
ErrorCode: Integer;
begin
ShellExec('', 'http://test.com', '', '', SW_SHOW, ewNoWait, ErrorCode);
end;
var
CustomPage: TWizardPage;
BtnImage: TBitmapImage;
procedure InitializeWizard;
begin
CustomPage := CreateCustomPage(wpLicense, 'Heading', 'Sub heading.');
ExtractTemporaryFile('image.bmp');
BtnImage := TBitmapImage.Create(WizardForm);
with BtnImage do
begin
Parent := CustomPage.ID;
Bitmap.LoadFromFile(ExpandConstant('{tmp}')+'\image.bmp');
AutoSize := True;
Left := 90;
Top := WizardForm.SelectTasksPage.Top + WizardForm.SelectTasksPage.Height - Height - 8;
Cursor := crHand;
OnClick := @ImageOnClick;
end;
end;
That's what TWizardPage.Surface
of type TNewNotebookPage
is for.
Also, never use absolute coordinates and sizes. Your layout will break, when the wizard is shown on high DPI/scaled display, what is quite common nowadays with "retina" displays. Use ScaleX
and ScaleY
functions. For the same reason, you should have images with different resolutions ready (see Inno Setup WizardImageFile looks bad with font scaling on Windows 7). Or at least scale/stretch the bitmap.
CustomPage := CreateCustomPage(wpLicense, 'Heading', 'Sub heading.');
ExtractTemporaryFile('image.bmp');
BtnImage := TBitmapImage.Create(WizardForm);
with BtnImage do
begin
Parent := CustomPage.Surface;
Bitmap.LoadFromFile(ExpandConstant('{tmp}')+'\image.bmp');
AutoSize := True;
AutoSize := False;
Height := ScaleX(Height);
Width := ScaleY(Width);
Stretch := True;
Left := ScaleX(90);
Top := WizardForm.SelectTasksPage.Top + WizardForm.SelectTasksPage.Height -
Height - ScaleY(8);
Cursor := crHand;
OnClick := @ImageOnClick;
end;
Layout on 100% zoom (96 DPI):
Layout on 150% zoom (144 DPI):
Layout on 150% zoom (144 DPI) with offset/sizes scaling and image stretching:
you can Use Botva2 library
http://krinkels.org/threads/botva2.1931/
use google translate if u can't understand rusian
u can create some awesome installer using this
image f.e
Botva2 example
[code]
#include "botva2.iss"
var SomeImage : Longint;
procedure InitializeWizard();
begin
{Your Custom page Code Goes Here}
SomeImage := ImgLoad(WizardForm.Handle,'Image.bmp',0,0,854,480,true,true);
end;
procedure CurPageChanged(CurPageID: Integer);
begin
ImgSetVisibility(SomeImage,false);
if (CurPageID = CustomPage.ID) ImgSetVisibility(SomeImage,true);
end;
Similar to Martin Prikryl's answer.
In order to deal with different DPI settings and placing a bitmap:
- setup your machine to 100% DPI
- make a bitmap with size (width/height) to fit on your InnoSetup page/form
- get these width and height (right click/properties on your bmp file)
- use the code below
- setup your machine to 150% DPI and create your bitmap to fit for 150% DPI and use it instead the first one (which fits for 100% DPI), this way it will look nice for 100% and for 200%
The code:
WarningImage := TBitmapImage.Create(RisksForm);
WarningImage.Parent := RisksForm;
WarningImage.Bitmap.LoadFromFile(ExpandConstant('{app}')+'uninstall-warning-large.bmp');
WarningImage.Left := ScaleX(24);
WarningImage.Top := ScaleY(120);
WarningImage.Width := ScaleX(544);
WarningImage.Height := ScaleY(211);
WarningImage.Stretch := True;
Change 544 with the width of your bitmap and 211 with the height of your bitmap (from step 3)
Stretch := True does the bitmap to expand (if it is smaller) or shrink (if it is bigger) than width/height properties
P.S. ofcourse you could use multiple files and use one depending on users DPI settings (DPI settings with Inno Setup), but bitmaps are without compressions, so I don't like this idea.