10

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;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
778899
  • 329
  • 3
  • 12

3 Answers3

10

That's what TWizardPage.Surface of type TNewNotebookPage is for.

with BtnImage do
begin
  Parent := CustomPage.Surface;
  { ... }
end;

Related questions:


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 := ScaleY(Height);
  Width := ScaleX(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 100% zoom (96 DPI)

Layout on 150% zoom (144 DPI):

Layout on 150% zoom (144 DPI)

Layout on 150% zoom (144 DPI) with offset/sizes scaling and image stretching:

Layout on 150% zoom (144 DPI) with offset/sizes scaling and image stretching

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
0

Similar to Martin Prikryl's answer. In order to deal with different DPI settings and placing a bitmap:

  1. setup your machine to 100% DPI
  2. make a bitmap with size (width/height) to fit on your InnoSetup page/form
  3. get these width and height (right click/properties on your bmp file)
  4. use the code below
  5. 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.

vinsa
  • 1,132
  • 12
  • 25
-1

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;
unknown.prince
  • 710
  • 6
  • 19
  • How does this answer the question? – Martin Prikryl Apr 29 '17 at 19:05
  • SomeImage := ImgLoad(WizardForm.Handle,'Image.bmp',0,0,854,480,true,true); procedure CurPageChanged(CurPageID: Integer); begin ImgSetVisibility(SomeImage,false); if (CurPageID = CustomPage.ID) ImgSetVisibility(SomeImage,true); – unknown.prince Apr 29 '17 at 19:19
  • actually procedure InitializeWizard(); var SomeImage:Longint; {SomeImage Should be a global variable} {CreateCustom Form Definition} SomeImage := ImgLoad(WizardForm.Handle,'Image.bmp',0,0,854,480,true,true)‌​; end; – unknown.prince Apr 29 '17 at 19:29
  • @PrinceGupta : please edit your answer and put code not in comments! – moskito-x Apr 30 '17 at 00:32
  • Using `CurPageChanged` to hide/show controls for respective page is a bad practice - Set control's parent to respective page instead! That's what the pages are for! – Martin Prikryl Apr 30 '17 at 07:13
  • use CustomePage.Surface.handle instead of WizardForm.Handle, also after calling Imgload call ImgApplyChanges(Custompage.Surface.Handle) this willl not require CurpageChanged function – unknown.prince May 01 '17 at 13:37
  • If you know that, why does your answer show that bad solution? – Martin Prikryl May 02 '17 at 08:49
  • for big scripts like https://i.stack.imgur.com/Ux6YI.jpg - we prefer not to create new components to save startup time and uses CurpageChanged functions a lot – unknown.prince May 02 '17 at 11:42