0

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

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Alexander Smith
  • 369
  • 2
  • 16

1 Answers1

1

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;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992