在卸载结束时显示自定义页面



我正试图找到一种方法,在卸载结束时显示"卸载完成"页面,如安装结束时显示的"安装完成"页面,并在同一时间跳过/隐藏自动卸载完成提示框。

我已经尝试过CreateCustomPage或其他创建页面函数,但这不能工作,因为我得到一个消息,告诉这些函数不能在卸载过程中调用…

那么,有没有一种方法可以显示(并控制)这样的页面呢?

或者我必须处理唯一的卸载完成提示框?

我的第一个目标是在这个页面上显示一个复选框,让用户选择打开或不打开尚未卸载的数据文件夹…

我尝试添加一个面板和一个位图来测试我的自定义表单上的这些组件。

我没有错误,'BitmapFileName'中的路径是可以的,但是面板和位图都没有显示:

procedure FormCheckOuvrirRepDonnees();
var
  Form: TSetupForm;
  OKButton: TNewButton;
  CheckBox: TNewCheckBox;
  Label1: TNewStaticText;
  Label2: TLabel;
  Panel: TPanel;
  BitmapImage: TBitmapImage;
  BitmapFileName: String;
begin
  Form := CreateCustomForm();
  try
    Form.ClientWidth := ScaleX(700);
    Form.ClientHeight := ScaleY(500);
    Form.Caption := ExpandConstant('{#MyAppName} {#MyAppVersion}');
    //Form.CenterInsideControl(WizardForm, False);
    Form.Center;
    Label1 := TNewStaticText.Create(Form);
    Label1.Parent := Form;
    //Label1.Width := Form.ClientWidth - ScaleX(2 * 10);
    Label1.AutoSize := true;
    Label1.Height := ScaleY(50);
    Label1.Left := ScaleX(325);
    Label1.Top := ScaleY(10);
    Label1.Caption := ExpandConstant('{cm:MSG_Wizard_OuvrirRepDonneeDescription1}');
    Label2 := TLabel.Create(Form);
    Label2.Parent := Form;
    //Label1.Width := Form.ClientWidth - ScaleX(2 * 10);
    Label2.AutoSize := true;
    Label2.Height := ScaleY(50);
    Label2.Left := ScaleX(325);
    Label2.Top := ScaleY(60);
    Label2.Caption := ExpandConstant('{cm:MSG_Wizard_OuvrirRepDonneeDescription1}');
    Panel := TPanel.Create(Form);
    Panel.Top := ScaleY(120);
    Panel.Width := Form.ClientWidth - ScaleX(2 * 10);
    Panel.Left := ScaleX(325);
    Panel.Height := ScaleY(50);
    Panel.Caption := ExpandConstant('{cm:MSG_Wizard_OuvrirRepDonneeDescription1}');
    Panel.Color := clWindow;
    //Panel.ParentBackground := False;
    //Panel.Parent := Form.Surface;
    BitmapImage := TBitmapImage.Create(Form);
    BitmapImage.Left := Form.left;
    BitmapImage.top := Form.top;
    BitmapImage.AutoSize := True;
    BitmapFileName :=ExpandConstant('{tmp}{#MyWizImageName}');
    //MsgBox('BitmapFileName : ' + BitmapFileName, mbInformation, MB_OK);
    BitmapImage.Bitmap.LoadFromFile(BitmapFileName);
    //BitmapImage.Cursor := crHand;
    CheckBox := TNewCheckBox.Create(Form);
    CheckBox.Parent := Form;
    CheckBox.Width := Form.ClientWidth - ScaleX(2 * 10);
    CheckBox.Height := ScaleY(17);
    CheckBox.Left := ScaleX(325);
    CheckBox.Top := ScaleY(200);
    CheckBox.Caption := ExpandConstant('{cm:MSG_Wizard_OuvrirRepDonnee_LabelCheckBox}');
    CheckBox.Checked := False;
    OKButton := TNewButton.Create(Form);
    OKButton.Parent := Form;
    OKButton.Width := ScaleX(75);
    OKButton.Height := ScaleY(23);
    OKButton.Left := ((Form.ClientWidth - OKButton.Width)/2);
    OKButton.Top := Form.ClientHeight - ScaleY(23 + 10);
    OKButton.Caption := 'OK';
    OKButton.ModalResult := mrOk;
    OKButton.Default := True;
    //CancelButton := TNewButton.Create(Form);
    //CancelButton.Parent := Form;
    //CancelButton.Width := ScaleX(75);
    //CancelButton.Height := ScaleY(23);
    //CancelButton.Left := Form.ClientWidth - ScaleX(75 + 10);
    //CancelButton.Top := Form.ClientHeight - ScaleY(23 + 10);
    //CancelButton.Caption := 'Cancel';
    //CancelButton.ModalResult := mrCancel;
    //CancelButton.Cancel := True;
    Form.ActiveControl := OKButton;
    if Form.ShowModal = mrOk then begin
      if CheckBox.Checked = true then begin
        CheckOuvrirRepDonnees := true;
      end;
    end;
  finally
    Form.Free();
  end;
end;

有人知道哪里出了问题吗?

您不能更改或添加/的向导页面到卸载程序-不支持CreateCustomPage()。

但是你可以用CreateCustomForm()(而不是CreateCustomPage)和ShowModal()显示自定义表单,用MsgBox()显示消息框,像这样

[Code]
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  if CurUninstallStep = usPostUninstall then
  begin
    // this is MsgBox will display after uninstall
    if MsgBox('Go to data folder?', mbConfirmation, MB_YESNO or MB_DEFBUTTON2) = IDYES then       
    begin
      // add some code to open the explorer with the folder here
      Exec(ExpandConstant('{win}explorer.exe'), 'c:datafolder', '', SW_SHOW, ewNoWait, ResultCode);
    end;
  end;
end;

如果你想显示复选框,那么CreateCustomForm()是可行的。

您可以尝试如下代码:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}My Program
DefaultGroupName=My Program
DisableProgramGroupPage=yes
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes
DirExistsWarning=no             
DisableDirPage=yes                        
[Files]
Source: "MyProg.exe"; DestDir: "{app}"
Source: "MyProg.chm"; DestDir: "{app}"
Source: "Readme.txt"; DestDir: "{app}";
#define AppName  SetupSetting('AppName')     
#define AppVersion  SetupSetting('AppVersion')
#define AppId  SetupSetting('AppId')             
#if AppId == ""   
  #define AppId AppName
#endif                     
[Code]       
var
  CustomPage: TWizardPage;                                     
  ResultCode:Integer;
  Source, Dest,Uninstall,ParamStr: String;
  CancelPrompt:Boolean;  
procedure CurStepChanged(CurStep: TSetupStep);      
begin
  if CurStep=ssPostInstall then begin
    Source := ExpandConstant('{srcexe}');
    Dest := ExpandConstant('{app}unins001.exe');               
    Exec('cmd.exe', '/c COPY "'+Source+'" "'+Dest+'"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);    
  end;                                                                                                                                                                                                                      
end;
function IsUnInstall(): Boolean;
begin
  Result := Pos('/CUNINSTALL',UpperCase(GetCmdTail)) > 0;
end;
function ShouldSkipPage(PageID: Integer): Boolean;
begin                                  
  Result := False;
  if IsUnInstall() then begin
    if PageID <> wpWelcome then     
      case PageID of
        CustomPage.ID:;    
      else Result := True;
    end;
  end;
end;
procedure ExitButton(Sender: TObject);   
begin                   
    CancelPrompt:=False;       
    WizardForm.Close;                                             
    Source := ExpandConstant('{src}');                  
    Exec('cmd.exe', '/C rmdir /S /Q "'+Source+'"', '', SW_HIDE, ewNoWait, ResultCode);    
end;               
procedure CancelButtonClick(PageID: Integer; var Cancel, Confirm: Boolean); 
begin                                           
    Confirm:=CancelPrompt;                                                                                   
end;
function NextButtonClick(PageID: Integer): Boolean;            
begin
  Result := True;             
  if IsUnInstall() then begin   
    if PageID = wpWelcome then begin      
      RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWAREMicrosoftWindowsCurrentVersionUninstall{#AppId}_is1','UninstallString', Uninstall);
      Exec(RemoveQuotes(Uninstall), ' /RECAll /SILENT' , '', SW_SHOW, ewWaitUntilTerminated, ResultCode);      
    end;
  end;
end;     
function CreatePage(var Page:TWizardPage;PageId:Integer):Integer;    
begin
  Page := CreateCustomPage(PageId, ExpandConstant('AAA'),ExpandConstant('BBB'));           
end;     
procedure CurPageChanged(PageID: Integer);
begin                                       
  if IsUnInstall() then begin   
    if PageID = CustomPage.ID then begin          
      with WizardForm do begin      
        CancelButton.Left:= NextButton.Left;
        CancelButton.Caption:=ExpandConstant('Finish');                                
        CancelButton.OnClick := @ExitButton;
        NextButton.Visible := False;          
        BackButton.Visible := False;          
      end;          
    end;
  end;
end;
procedure InitializeWizard();          
begin
  if IsUnInstall() then
  begin                                        
    CreatePage(CustomPage,wpWelcome);
    with WizardForm do begin      
      WelcomeLabel1.Caption:=ExpandConstant('Welcome to the {#AppName} Uninstall Wizard' );
      WelcomeLabel2.Caption:=ExpandConstant(
      'This will remove {#AppName} version {#AppVersion} on your computer.' +#13+
      ''+#13+
      'It is recommended that you close all other applications before continuing.'+#13+
      ''+#13+
      'Click Next to continue, or Cancel to exit Setup.'
      );
    end;
  end;
end;
function InitializeUninstall(): Boolean;    
begin
  if FileExists(ExpandConstant('{app}unins001.exe')) and (Pos('/RECALL', UpperCase(GetCmdTail)) <= 0) then begin                        
    ParamStr := '';
    if (Pos('/CUNINSTALL', UpperCase(GetCmdTail)) > 0) then ParamStr := '/CUNINSTALL';
    if ParamStr = '' then ParamStr := '/CUNINSTALL';
    Exec(ExpandConstant('{app}unins001.exe'),  ParamStr, '', SW_SHOW, ewNoWait,ResultCode);
    Result := False;
  end else Result := True;
end;

最新更新