5

Is it possible to have an image button in Inno Wizard page instead of a plain Caption Text?

What I would like to accomplish is to create an Off/On image button to mute/play a music while Inno setup is running.

Thanks!

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Drakul
  • 119
  • 5

1 Answers1

6

There's no direct support for setting images for buttons in Inno Setup.

So you have to revert to Win32 API.

function LoadImage(hInst: Integer; ImageName: string; ImageType: UINT;
  X, Y: Integer; Flags: UINT): THandle;
  external 'LoadImageW@User32.dll stdcall';
function ImageList_Add(ImageList: THandle; Image, Mask: THandle): Integer;
  external 'ImageList_Add@Comctl32.dll stdcall';
function ImageList_Create(CX, CY: Integer; Flags: UINT;
  Initial, Grow: Integer): THandle;
  external 'ImageList_Create@Comctl32.dll stdcall';

const
  IMAGE_BITMAP = 0;
  LR_LOADFROMFILE = $10;
  ILC_COLOR32 = $20;
  BCM_SETIMAGELIST = $1600 + $0002;

type
  BUTTON_IMAGELIST = record
    himl: THandle;
    margin: TRect;
    uAlign: UINT;
  end;

function SendSetImageListMessage(
  Wnd: THandle; Msg: Cardinal; WParam: Cardinal;
  var LParam: BUTTON_IMAGELIST): Cardinal;
  external 'SendMessageW@User32.dll stdcall';

function InitializeSetup(): Boolean;
var
  ImageList: THandle;
  Image: THandle;
  ButtonImageList: BUTTON_IMAGELIST;
begin
  ImageList := ImageList_Create(16, 16, ILC_COLOR32, 1, 1);
  Image := LoadImage(0, 'button.bmp', IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

  ImageList_Add(ImageList, Image, 0);

  ButtonImageList.himl := ImageList;

  SendSetImageListMessage(
    WizardForm.NextButton.Handle, BCM_SETIMAGELIST, 0, ButtonImageList);
end;

enter image description here

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • 2
    Yep! I think that´s the way to go... Great! Thanks for the hint... Was a bit lost there... – Drakul Feb 01 '16 at 13:59