具有三个按钮和三个结果的Inno Setup MsgBox [英] Inno Setup MsgBox with three buttons and three outcomes
问题描述
我正在尝试创建具有三个按钮和三个结果的MsgBox
,但是看不到如何创建第三个结果?目前,对于两个按钮MsgBox
,我有以下代码,它们可以正常工作:
I am trying to create a MsgBox
with three buttons and three outcomes, but am unable to see how I can create the third outcome? I currently have the following code for a two button MsgBox
, which works perfectly:
if ((strExistingInstallPath <> '') and (strExistingVersion = '2.5.3')) then
begin
if 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, IDYES) = IDYES then
begin
Exec(GetUninstallString, '', '', SW_SHOW,
ewWaitUntilTerminated, intResultCode);
Result := True;
end else
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;
end;
如果将MB_YESNO
更改为MB_YESNOCANCEL
,我现在会得到三个按钮,分别是是,否和取消.但是,由于if
语句已分配给MsgBox
,所以我正在努力找出如何执行else if IDCANCEL then
类型语句.我试图将MsgBox返回的ID常量分配给一个字符串,然后为该字符串创建单独的if语句,该语句等于每个ID常量,但这不幸地失败了.我在这里想念什么?理想情况下,我希望将三个按钮分别标记为是,否和 Silent ,以便为第三个按钮指定/silent
参数以防止出现卸载提示.那么,是否也可以重命名按钮?
If I change the MB_YESNO
to MB_YESNOCANCEL
, I now get three buttons, Yes, No and Cancel. However, since the if
statement is assigned to the MsgBox
, I'm struggling to work out how to do an else if IDCANCEL then
type statement. I tried to assign the ID constant returned by the MsgBox to a string and then create separate if statements for the string being equal to each ID constant, but this failed miserably. What am I missing here? Ideally, I would like the three buttons be labelled as Yes, No and Silent, so that the third button can be given a /silent
parameter to prevent the uninstall prompt. So, is it possible to rename the buttons as well?
推荐答案
您可以编写多个if
语句,但是必须将返回的值存储到变量中并检查该变量值.但是正如@Sertac在其评论中提到的那样,您可以使用case
语句,该语句可以更好地描述代码中的目标,例如:
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;
出于好奇,有多个if
语句可能是:
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;
这篇关于具有三个按钮和三个结果的Inno Setup MsgBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!