【问题标题】:How to add Music ON/OFF functionality button?如何添加音乐开/关功能按钮?
【发布时间】:2020-05-04 14:19:11
【问题描述】:

如何在除“已完成”页面之外的所有向导页面的左下角添加音乐开/关功能按钮。并且只有在用户点击“完成”按钮后,正在播放的音乐才会停止。

    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;

【问题讨论】:

  • 您是在问如何创建按钮或如何开始/停止音乐或两者兼而有之(这是两个独立的主题)?

标签: inno-setup pascalscript


【解决方案1】:

要在底部面板上创建按钮,请参阅:
How to create new About button in Inno Setup?


背景音乐请见:
Playing sound during an Inno Setup install


要在按钮单击时停止音乐播放,只需从 OnClick 处理程序调用 DSStopMediaPlay (Inno Media Player)。

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

要隐藏已完成页面上的按钮,您需要保存对全局变量的按钮引用并在CurPageChanged(wpFinished) 中设置.Visible = false

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

当然,您希望将变量命名为StopButton,而不是AboutButton

【讨论】:

  • 这是我的 iss 脚本。我收到错误重复标识符“InitializeWizard”
  • 我按照您的演示完成了所有程序。我不知道帕斯卡编程所以请帮助
  • 抱歉,我不会为了获取您的 .iss 而从随机网页下载一些 .exe 文件。上传到别处。或者只是将代码附加到您的问题中。无论如何,您的代码中可能有多个InitializeWizard 过程。只需将beginend 之间的代码合并到一个过程中即可。见I have duplicated InitializeSetup in INNO SETUP how can i solve it?
  • 不,我已经上传了我的 .iss 文件,它在 kb 中
  • 反正我再试一次
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-23
  • 1970-01-01
  • 1970-01-01
  • 2021-04-13
相关资源
最近更新 更多