Inno Setup - How to create a OuterNotebook/welcome page in the uninstaller?

南笙酒味 提交于 2019-12-19 04:49:08

问题


I am using this code from the answer by Martin Prikryl to Custom Uninstall page (not MsgBox).

How to modify the first page of this code to show a "Welcome"-like page on the OuterNotebook page (i.e. without the MainPanel header)?


回答1:


You create the page as any other, except that its parent will be the UninstallProgressForm.OuterNotebook, not the .InnerNotebook.

Tricky part is not how to create the page, but how to implement the Next/Back buttons.

The Next button on the "welcome" page must change the page of the OuterNotebook from the "welcome" page to the UninstallProgressForm.InnerPage. And of course make sure the active page on the .InnerNotebook is the first normal/inner page.

Conversely, the Back button on the first normal/inner page must change the page of the OuterNotebook from the UninstallProgressForm.InnerPage to the "welcome" page.

So modifying my answer to the Custom Uninstall page (not MsgBox) to cater for the above, you will get:

[Files]
Source: "compiler:WizModernImage-IS.bmp"; DestDir: {app}

[Code]

var
  UninstallWelcomePage: TNewNotebookPage;
  UninstallFirstPage: TNewNotebookPage;
  UninstallSecondPage: TNewNotebookPage;
  UninstallBackButton: TNewButton;
  UninstallNextButton: TNewButton;

procedure UpdateUninstallWizard;
begin
  if UninstallProgressForm.InnerNotebook.ActivePage = UninstallFirstPage then
  begin
    UninstallProgressForm.PageNameLabel.Caption := 'First uninstall wizard page';
    UninstallProgressForm.PageDescriptionLabel.Caption :=
      'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
  end
    else
  if UninstallProgressForm.InnerNotebook.ActivePage = UninstallSecondPage then
  begin
    UninstallProgressForm.PageNameLabel.Caption := 'Second uninstall wizard page';
    UninstallProgressForm.PageDescriptionLabel.Caption :=
      'Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
  end;

  UninstallBackButton.Visible :=
    (UninstallProgressForm.OuterNotebook.ActivePage <> UninstallWelcomePage);

  if UninstallProgressForm.InnerNotebook.ActivePage <> UninstallSecondPage then
  begin
    UninstallNextButton.Caption := SetupMessage(msgButtonNext);
    UninstallNextButton.ModalResult := mrNone;
  end
    else
  begin
    UninstallNextButton.Caption := 'Uninstall';
    { Make the "Uninstall" button break the ShowModal loop }
    UninstallNextButton.ModalResult := mrOK;
  end;
end;  

procedure UninstallNextButtonClick(Sender: TObject);
begin
  if UninstallProgressForm.OuterNotebook.ActivePage = UninstallWelcomePage then
  begin
    UninstallProgressForm.OuterNotebook.ActivePage := UninstallProgressForm.InnerPage;
    UninstallProgressForm.InnerNotebook.ActivePage := UninstallFirstPage;
    UpdateUninstallWizard;
  end
    else
  begin
    if UninstallProgressForm.InnerNotebook.ActivePage <> UninstallSecondPage then
    begin
      if UninstallProgressForm.InnerNotebook.ActivePage = UninstallFirstPage then
      begin
        UninstallProgressForm.InnerNotebook.ActivePage := UninstallSecondPage;
      end;
      UpdateUninstallWizard;
    end
      else
    begin
      UninstallNextButton.Visible := False;
      UninstallBackButton.Visible := False;
    end;
  end;
end;

procedure UninstallBackButtonClick(Sender: TObject);
begin
  if UninstallProgressForm.InnerNotebook.ActivePage = UninstallFirstPage then
  begin
    UninstallProgressForm.OuterNotebook.ActivePage := UninstallWelcomePage;
  end
    else
  if UninstallProgressForm.InnerNotebook.ActivePage = UninstallSecondPage then
  begin
    UninstallProgressForm.InnerNotebook.ActivePage := UninstallFirstPage;
  end;

  UpdateUninstallWizard;
end;

procedure InitializeUninstallProgressForm();
var
  PageText: TNewStaticText;
  UninstallWizardBitmapImage: TBitmapImage;
  PageNameLabel: string;
  PageDescriptionLabel: string;
  CancelButtonEnabled: Boolean;
  CancelButtonModalResult: Integer;
begin
  if not UninstallSilent then
  begin
    PageNameLabel := UninstallProgressForm.PageNameLabel.Caption;
    PageDescriptionLabel := UninstallProgressForm.PageDescriptionLabel.Caption;

    { Create the Welcome page and make it active }
    UninstallWelcomePage := TNewNotebookPage.Create(UninstallProgressForm);
    UninstallWelcomePage.Notebook := UninstallProgressForm.OuterNotebook;
    UninstallWelcomePage.Parent := UninstallProgressForm.OuterNotebook;
    UninstallWelcomePage.Align := alClient;
    UninstallWelcomePage.Color := clWindow;

    UninstallWizardBitmapImage := TBitmapImage.Create(UninstallProgressForm);
    UninstallWizardBitmapImage.Parent := UninstallWelcomePage;
    UninstallWizardBitmapImage.Width := ScaleX(164);
    UninstallWizardBitmapImage.Height := ScaleX(314);
    UninstallWizardBitmapImage.Bitmap.LoadFromFile(
      ExpandConstant('{app}\WizModernImage-IS.bmp'));
    UninstallWizardBitmapImage.Center := True;
    UninstallWizardBitmapImage.Stretch := True;

    PageText := TNewStaticText.Create(UninstallProgressForm);
    PageText.Parent := UninstallWelcomePage;
    PageText.Left := ScaleX(176);
    PageText.Top := ScaleX(16);
    PageText.Width := ScaleX(301);
    PageText.Height := ScaleX(54);
    PageText.AutoSize := False;
    PageText.Caption := 'Welcome to the My Program uninstall wizard';
    PageText.ShowAccelChar := False;
    PageText.WordWrap := True;
    PageText.Font.Name := 'Verdana';
    PageText.Font.Size := 12;
    PageText.Font.Style := [fsBold];

    PageText := TNewStaticText.Create(UninstallProgressForm);
    PageText.Parent := UninstallWelcomePage;
    PageText.Left := ScaleX(176);
    PageText.Top := ScaleX(76);
    PageText.Width := ScaleX(301);
    PageText.Height := ScaleX(234);
    PageText.AutoSize := False;
    PageText.Caption :=
      'This will uninstall My Program 1.5 from your computer.'#13#10#13#10 +
      'It is recommended that your close all other applications before continuing.' +
        #13#10#13#10 +
      'Click Next to continue, or Cancel to exit Uninstall.';
    PageText.ShowAccelChar := False;
    PageText.WordWrap := True;

    UninstallProgressForm.OuterNotebook.ActivePage := UninstallWelcomePage;

    { Create the first page }
    UninstallFirstPage := TNewNotebookPage.Create(UninstallProgressForm);
    UninstallFirstPage.Notebook := UninstallProgressForm.InnerNotebook;
    UninstallFirstPage.Parent := UninstallProgressForm.InnerNotebook;
    UninstallFirstPage.Align := alClient;

    PageText := TNewStaticText.Create(UninstallProgressForm);
    PageText.Parent := UninstallFirstPage;
    PageText.Top := UninstallProgressForm.StatusLabel.Top;
    PageText.Left := UninstallProgressForm.StatusLabel.Left;
    PageText.Width := UninstallProgressForm.StatusLabel.Width;
    PageText.Height := UninstallProgressForm.StatusLabel.Height;
    PageText.AutoSize := False;
    PageText.ShowAccelChar := False;
    PageText.Caption := 'Press Next to proceeed with uninstallation.';

    { Create the second page }
    UninstallSecondPage := TNewNotebookPage.Create(UninstallProgressForm);
    UninstallSecondPage.Notebook := UninstallProgressForm.InnerNotebook;
    UninstallSecondPage.Parent := UninstallProgressForm.InnerNotebook;
    UninstallSecondPage.Align := alClient;

    PageText := TNewStaticText.Create(UninstallProgressForm);
    PageText.Parent := UninstallSecondPage;
    PageText.Top := UninstallProgressForm.StatusLabel.Top;
    PageText.Left := UninstallProgressForm.StatusLabel.Left;
    PageText.Width := UninstallProgressForm.StatusLabel.Width;
    PageText.Height := UninstallProgressForm.StatusLabel.Height;
    PageText.AutoSize := False;
    PageText.ShowAccelChar := False;
    PageText.Caption := 'Press Uninstall to proceeed with uninstallation.';

    UninstallNextButton := TNewButton.Create(UninstallProgressForm);
    UninstallNextButton.Parent := UninstallProgressForm;
    UninstallNextButton.Left :=
      UninstallProgressForm.CancelButton.Left -
      UninstallProgressForm.CancelButton.Width -
      ScaleX(10);
    UninstallNextButton.Top := UninstallProgressForm.CancelButton.Top;
    UninstallNextButton.Width := UninstallProgressForm.CancelButton.Width;
    UninstallNextButton.Height := UninstallProgressForm.CancelButton.Height;
    UninstallNextButton.OnClick := @UninstallNextButtonClick;

    UninstallBackButton := TNewButton.Create(UninstallProgressForm);
    UninstallBackButton.Parent := UninstallProgressForm;
    UninstallBackButton.Left :=
      UninstallNextButton.Left - UninstallNextButton.Width - ScaleX(10);
    UninstallBackButton.Top := UninstallProgressForm.CancelButton.Top;
    UninstallBackButton.Width := UninstallProgressForm.CancelButton.Width;
    UninstallBackButton.Height := UninstallProgressForm.CancelButton.Height;
    UninstallBackButton.Caption := SetupMessage(msgButtonBack);
    UninstallBackButton.OnClick := @UninstallBackButtonClick;
    UninstallBackButton.TabOrder := UninstallProgressForm.CancelButton.TabOrder;

    UninstallNextButton.TabOrder := UninstallBackButton.TabOrder + 1;

    UninstallProgressForm.CancelButton.TabOrder := UninstallNextButton.TabOrder + 1;

    { Run our wizard pages } 
    UpdateUninstallWizard;
    CancelButtonEnabled := UninstallProgressForm.CancelButton.Enabled
    UninstallProgressForm.CancelButton.Enabled := True;
    CancelButtonModalResult := UninstallProgressForm.CancelButton.ModalResult;
    UninstallProgressForm.CancelButton.ModalResult := mrCancel;

    if UninstallProgressForm.ShowModal = mrCancel then Abort;

    { Restore the standard page payout }
    UninstallProgressForm.CancelButton.Enabled := CancelButtonEnabled;
    UninstallProgressForm.CancelButton.ModalResult := CancelButtonModalResult;

    UninstallProgressForm.PageNameLabel.Caption := PageNameLabel;
    UninstallProgressForm.PageDescriptionLabel.Caption := PageDescriptionLabel;

    UninstallProgressForm.InnerNotebook.ActivePage :=
      UninstallProgressForm.InstallingPage;
  end;
end;


Note that there's no way to use the built-in images from the installer in the uninstaller. In my simple code above, I install the "welcome" page image to the {app} and load it from there.

If you want to avoid this, see my answer to the How keep uninstall files inside uninstaller?



来源:https://stackoverflow.com/questions/42625626/inno-setup-how-to-create-a-outernotebook-welcome-page-in-the-uninstaller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!