0

How can I include a Music ON/OFF functionality button in the bottom left corner of all wizard pages except the Finished page. And the music being active should stop only after the user hit Finish button.

enter image description here

    procedure InitializeWizard();
begin
  // Welcome page
  // Hide the labels
  WizardForm.WelcomeLabel1.Visible := False;
  WizardForm.WelcomeLabel2.Visible := False;
  // Stretch image over whole page
  WizardForm.WizardBitmapImage.Width := WizardForm.WizardBitmapImage2.Parent.Width;

  begin with WizardForm.WizardSmallBitmapImage do SetBounds(Parent.Left, Parent.Top, Parent.Width, Parent.Height);
  WizardForm.PageDescriptionLabel.Visible := False;
  WizardForm.PageNameLabel.Visible := False; end;

  // Finished page
  // Hide the labels
  WizardForm.FinishedLabel.Visible := False;
  WizardForm.FinishedHeadingLabel.Visible := False;
  // Stretch image over whole page
  WizardForm.WizardBitmapImage2.Width := WizardForm.WizardBitmapImage2.Parent.Width;
end;

procedure AboutButtonOnClick(Sender: TObject);
begin
  MsgBox('This is the about message!', mbInformation, mb_Ok);
end;

procedure InitializeWizard();
  AboutButton : TNewButton;
begin
  // create an instance of the button and assign it to the local variable AboutButton
  AboutButton := TNewButton.Create(WizardForm);
  // set the parent to the just created button control
  AboutButton.Parent := WizardForm;
  // adjust the position to the created button control; it gets the horizontal indent
  // by the right indent of the Cancel button; the vertical position as well as width
  // and height are the same as the Cancel button has
  AboutButton.Left := WizardForm.ClientWidth - WizardForm.CancelButton.Left -
    WizardForm.CancelButton.Width;
  AboutButton.Top := WizardForm.CancelButton.Top;
  AboutButton.Width := WizardForm.CancelButton.Width;
  AboutButton.Height := WizardForm.CancelButton.Height;
  // set its caption
  AboutButton.Caption := '&About';
  // and assign the AboutButtonOnClick method to the OnClick event of the button
  AboutButton.OnClick := @AboutButtonOnClick;
end;

procedure AboutButtonOnClick(Sender: TObject);
begin
  MsgBox('This is the about message!', mbInformation, mb_Ok);
end;

const
  BASS_SAMPLE_LOOP = 4;
  BASS_UNICODE = $80000000;
  BASS_CONFIG_GVOL_STREAM = 5;
const
  #ifndef UNICODE
    EncodingFlag = 0;
  #else
    EncodingFlag = BASS_UNICODE;
  #endif
type
  HSTREAM = DWORD;

function BASS_Init(device: LongInt; freq, flags: DWORD;
  win: HWND; clsid: Cardinal): BOOL;
  external 'BASS_Init@files:bass.dll stdcall';
function BASS_StreamCreateFile(mem: BOOL; f: string; offset1: DWORD;
  offset2: DWORD; length1: DWORD; length2: DWORD; flags: DWORD): HSTREAM;
  external 'BASS_StreamCreateFile@files:bass.dll stdcall';
function BASS_ChannelPlay(handle: DWORD; restart: BOOL): BOOL;
  external 'BASS_ChannelPlay@files:bass.dll stdcall';
function BASS_SetConfig(option: DWORD; value: DWORD ): BOOL;
  external 'BASS_SetConfig@files:bass.dll stdcall';
function BASS_Free: BOOL;
  external 'BASS_Free@files:bass.dll stdcall';

procedure InitializeWizard;
var
  StreamHandle: HSTREAM;
begin
  ExtractTemporaryFile('AudioFile.mp3');
  if BASS_Init(-1, 44100, 0, 0, 0) then
  begin
    StreamHandle := BASS_StreamCreateFile(False,
      ExpandConstant('{tmp}\AudioFile.mp3'), 0, 0, 0, 0,
      EncodingFlag or BASS_SAMPLE_LOOP);
    BASS_SetConfig(BASS_CONFIG_GVOL_STREAM, 2500);
    BASS_ChannelPlay(StreamHandle, False);
  end;
end;

procedure DeinitializeSetup;
begin
  BASS_Free;
end;

procedure AboutButtonOnClick(Sender: TObject);
begin
  DSStopMediaPlay;
end;

var
  // Global variable
  AboutButton: TNewButton;

procedure InitializeWizard;
begin
  // create an instance of the button and assign it to the global variable AboutButton
  Music ON\OFF  := TNewButton.Create(WizardForm);
  ...
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  // Hide button on Finished page
  if CurPageID = wpFinished then
  begin
    AboutButton.Visible := False;
  end;
lone_wolf
  • 125
  • 2
  • 9

1 Answers1

0

To create a button on the bottom panel, see:
How to create new About button in Inno Setup?


For background music, see:
Playing sound during an Inno Setup install


To stop music playback on button click, just call DSStopMediaPlay (Inno Media Player) from the OnClick handler.

procedure AboutButtonOnClick(Sender: TObject);
begin
  DSStopMediaPlay;
end;

To hide the button on Finished page, you need to save a button reference to a global variable and set .Visible = false in CurPageChanged(wpFinished):

[Code]

var
  { Global variable }
  AboutButton: TNewButton;

procedure InitializeWizard;
begin
  { create an instance of the button and assign it to the global variable AboutButton }
  AboutButton := TNewButton.Create(WizardForm);
  ...
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  { Hide button on Finished page }
  if CurPageID = wpFinished then
  begin
    AboutButton.Visible := False;
  end;
end;

Of course, you want to name the variable StopButton, not AboutButton.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • This is my iss script. I'm getting error duplicate identifier 'InitializeWizard' – lone_wolf Jan 13 '16 at 04:19
  • I did all procedure as you demonstrated. I don't know pascal programming so plz help – lone_wolf Jan 13 '16 at 04:20
  • Sorry, but I'm not going to download some .exe file from a random webpage just to get your .iss. Upload it elsewhere. Or just append the code to your question. Anyway, you probably have multiple `InitializeWizard` procedures in your code. Just merge the code between `begin` and `end` into one procedure. See [I have duplicated InitializeSetup in INNO SETUP how can i solve it?](http://stackoverflow.com/q/24040732/850848) – Martin Prikryl Jan 13 '16 at 06:58
  • No I have uploaded my .iss file & it is in kb's – lone_wolf Jan 13 '16 at 08:17
  • Anyway I'm trying again – lone_wolf Jan 13 '16 at 08:17
  • Still couldn't make it right. Please Martin make the corrections in the iss over the link above. It's a very small file. – lone_wolf Jan 13 '16 at 08:32
  • Got it. I didn't notice that grey checkbox below the download button. – Martin Prikryl Jan 13 '16 at 08:33
  • Again, just take all the lines between `begin` and `end` of the second `InitializeWizard` procedure (starting with `// create an instance of the button ...`, ending with `... @AboutButtonOnClick;` and move that before the `end;` line of the first `InitializeWizard` procedure. And remove the rest of the second instance. Also the `AboutButton : TNewButton;` must be global, so add `var AboutButton : TNewButton;` just after the `[Code]`, as in my answer above. – Martin Prikryl Jan 13 '16 at 08:36
  • You also have two instances of the `AboutButtonOnClick`, remove the first with `MsgBox`. You do not need that. + The procedure has to be defined before it is used, so before the `InitializeWizard`. – Martin Prikryl Jan 13 '16 at 08:38
  • You use `DSStopMediaPlay` from (Inno Media Player) from the `AboutButtonOnClick`, yet you use the BASS library. That cannot work. – Martin Prikryl Jan 13 '16 at 08:38
  • I see you have the global `AboutButton` variable at the end. Again it has to be defined before it is used, so before the `InitializeWizard` (the first one, the only one). And remove the third instance of `InitializeWizard` (with the `Music ON\OFF`). – Martin Prikryl Jan 13 '16 at 08:40
  • Yeah I did. Now it says unknown identifier 'AboutButtonOnClick' – lone_wolf Jan 13 '16 at 08:44
  • Brother I have told you I don't know pascal programming..I didn't understand this all. Please just edit my .iss, it would be highly appreciating. Please.. – lone_wolf Jan 13 '16 at 08:47
  • It's the last thing I need to implement in my application setup – lone_wolf Jan 13 '16 at 08:48
  • StackOverflow is not a code writing service. We answer questions here. I've covered the `AboutButtonOnClick` above. – Martin Prikryl Jan 13 '16 at 08:48
  • Attach the code after the corrections you done already. The code you have attached still fails with `Duplicate identifier 'INITIALIZEWIZARD'`, not with `unknown identifier 'AboutButtonOnClick'`. – Martin Prikryl Jan 13 '16 at 09:09
  • Actually I accidently closed the script without saving changes. So now this only where I'm... – lone_wolf Jan 13 '16 at 09:11