Inno Setup MsgBox with three buttons and three outcomes

拜拜、爱过 提交于 2019-12-01 19:52:44
TLama

You could write multiple if statements, but you'd have to store the returned value into a variable and check that variable value. But as @Sertac mentioned in his comment, you can use a case statement, which better describes the aim in your code, for instance:

case SuppressibleMsgBox('Text', mbConfirmation, MB_YESNOCANCEL, IDYES) of
  IDYES:
  begin
    { user pressed Yes }
  end;
  IDNO:
  begin
    { user pressed No }
  end;
  IDCANCEL:
  begin
    { user pressed Cancel }
  end;
end;

Out of curiosity with multiple if statements it could be:

var
  MsgResult: Integer;
begin
  MsgResult := SuppressibleMsgBox('Text', mbConfirmation, MB_YESNOCANCEL, IDYES);

  if MsgResult = IDYES then
  begin
    { user pressed Yes }
  end
  else
  if MsgResult = IDNO then
  begin
    { user pressed No }
  end
  else
  if MsgResult = IDCANCEL then
  begin
    { user pressed Cancel }
  end;
end;
Robert Wigley

Here is the final code in case it is useful for anyone else:

var
  intMsgBoxResult: Integer;
if ((strExistingInstallPath <> '') and (strExistingVersion = '2.5.3')) then
begin
  intMsgBoxResult := SuppressibleMsgBox('Setup has detected that ' + strMyAppName + ' ' + strExistingVersion + '.' + strExistingBuild + ' is installed.' + #13#10 + #13#10 +
    'The existing version must be removed before installing or upgrading to ' + strMyAppVersion + '.' + strMyAppBuild + '.' + #13#10 + #13#10 +
    'Would you like Setup to uninstall the existing version?',
    mbConfirmation, MB_YESNO, IDIGNORE);
  if intMsgBoxResult = IDYES then
    begin
      Exec(GetUninstallString, '/silent', '', SW_SHOW,
        ewWaitUntilTerminated, intResultCode);
      Result := True;
    end;
  if intMsgBoxResult = IDNO then 
    begin
      MsgBox('The existing version must be removed first.' + #13#10 +
        'Setup is unable to continue. Setup will now exit.',
        mbError, MB_OK);
      Result := False;
    end;
  if intMsgBoxResult = IDIGNORE then
    begin
      Exec(GetUninstallString, '', '', SW_SHOW,
        ewWaitUntilTerminated, intResultCode);
      Result := True;
    end; 
end;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!