Inno Setup Disable close button (X)

2019-04-17 07:40发布

How to disable the Close button (borderstyle)?

I want to combine that with hiding "About Setup" command from system menu:
Inno Setup - BorderIcons dropdown menu

标签: inno-setup
1条回答
甜甜的少女心
2楼-- · 2019-04-17 08:13

Use EnableMenuItem WinAPI function:

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_GRAYED = $1;
  MF_BYCOMMAND = $0;
  SC_CLOSE = $F060;

procedure DisableCloseButton;
var
  Menu: THandle;
begin
  Menu := GetSystemMenu(WizardForm.Handle, False);
  EnableMenuItem(Menu, SC_CLOSE, MF_BYCOMMAND or MF_GRAYED);
end;

You have to call the DisableCloseButton later than from the InitializeWizard event function.

There maybe a better place to call it, but for a simplicity you can call it from CurPageChanged:

procedure CurPageChanged(CurPageID: Integer);
begin
  DisableCloseButton;
end;

But note that you need to keep the code to hide "About Setup" command in InitializeWizard as that needs to be called only once (and it works there correctly).

The screenshot shows both codes combined:

enter image description here

查看更多
登录 后发表回答