By 778899


2017-04-29 14:00:14 8 Comments

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;

3 comments

@vinsa 2019-03-26 18:55:44

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.

@Prince Gupta 2017-04-29 18:36:25

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;

@Martin Prikryl 2017-04-29 19:05:42

How does this answer the question?

@Prince Gupta 2017-04-29 19:19:26

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);

@Prince Gupta 2017-04-29 19:29:49

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;

@moskito-x 2017-04-30 00:32:27

@PrinceGupta : please edit your answer and put code not in comments!

@Martin Prikryl 2017-04-30 07:13:04

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!

@Prince Gupta 2017-05-01 13:37:59

use CustomePage.Surface.handle instead of WizardForm.Handle, also after calling Imgload call ImgApplyChanges(Custompage.Surface.Handle) this willl not require CurpageChanged function

@Martin Prikryl 2017-05-02 08:49:09

If you know that, why does your answer show that bad solution?

@Prince Gupta 2017-05-02 11:42:43

for big scripts like i.stack.imgur.com/Ux6YI.jpg - we prefer not to create new components to save startup time and uses CurpageChanged functions a lot

@Martin Prikryl 2017-04-29 17:02:53

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 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

Related Questions

Sponsored Content

1 Answered Questions

[SOLVED] Inno Setup - Customize installing page

  • 2017-06-29 21:28:49
  • user3796104
  • 658 View
  • 2 Score
  • 1 Answer
  • Tags:   inno-setup

4 Answered Questions

[SOLVED] Inno Setup for Windows service?

2 Answered Questions

[SOLVED] Inno Setup Place controls on wpPreparing Page

2 Answered Questions

[SOLVED] Inno Setup custom welcome page

  • 2009-12-03 06:01:16
  • user93202
  • 6008 View
  • 4 Score
  • 2 Answer
  • Tags:   inno-setup

0 Answered Questions

Inno setup custom message

  • 2014-05-01 22:04:40
  • user3352424
  • 908 View
  • 0 Score
  • 0 Answer
  • Tags:   inno-setup

0 Answered Questions

Inno Setup Custom Installing Page

  • 2014-06-20 11:23:04
  • Myanju
  • 300 View
  • 2 Score
  • 0 Answer
  • Tags:   inno-setup

0 Answered Questions

Custom wizard page - Inno setup

  • 2014-03-13 18:19:36
  • Andre Garcia
  • 430 View
  • 1 Score
  • 0 Answer
  • Tags:   inno-setup

1 Answered Questions

[SOLVED] Inno setup : Custom messages

  • 2013-07-29 11:59:04
  • user1752602
  • 3135 View
  • 1 Score
  • 1 Answer
  • Tags:   inno-setup

1 Answered Questions

[SOLVED] inno setup bmp image appear on a single page

  • 2012-10-17 16:38:08
  • Marcio
  • 3094 View
  • 7 Score
  • 1 Answer
  • Tags:   inno-setup

1 Answered Questions

[SOLVED] Inno Setup custom page

  • 2010-11-30 08:58:52
  • thedev
  • 16235 View
  • 6 Score
  • 1 Answer
  • Tags:   inno-setup

Sponsored Content