inno-setup

Enable close/cancel button of Inno Setup on Finished page


Is it possible to enable close button on the final page of Inno Setup form, and add behaviour of an exit?

enter image description here


Solution

  • It's easy to enable the close button, use EnableMenuItem WinAPI function. See also Inno Setup Disable close button (X).

    Difficult is to make the close button working actually. Inno Setup window is not designed to be closed on the "Finished" page. The only way is probably to forcefully abort the process using ExitProcess WinAPI function. See Exit from Inno Setup installation from [Code].

    The complete code would be:

    function GetSystemMenu(hWnd: THandle; bRevert: Boolean): THandle;
      external 'GetSystemMenu@user32.dll stdcall';
    
    function EnableMenuItem(hMenu: UINT; uIDEnableItem, uEnable: UINT): Boolean;
      external 'EnableMenuItem@user32.dll stdcall';
    
    const
      MF_BYCOMMAND = $0;
      SC_CLOSE = $F060;
    
    procedure ExitProcess(exitCode:integer);
      external 'ExitProcess@kernel32.dll stdcall';
    
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      Log('Exiting by user after installation');
      ExitProcess(1);
    end;
    
    procedure CurPageChanged(CurPageID: Integer);
    var
      Menu: THandle;
    begin
      if CurPageID = wpFinished then
      begin
        // Enable "close" button
        Menu := GetSystemMenu(WizardForm.Handle, False);
        EnableMenuItem(Menu, SC_CLOSE, MF_BYCOMMAND);
        // Make the "close" button working
        WizardForm.OnClose := @FormClose;
      end;
    end;