[英]How do I capture the results of a YESNOCANCEL MessageBox without gotos/labels in NSIS installer scripting?
我想知道如何在NSIS安裝程序腳本中使用YESNOCANCEL MessageBox和LogicLib.nsh中的IF邏輯,以避免使用標簽和gotos。
有沒有辦法在某種變量中捕獲MessageBox的結果?
此外,我知道有比NSIS更好的東西,但在這一點上使用其他東西不是可能的。 =(
請注意以下代碼中的{WHAT GOES HERE??}
。 如果這只是一個If ... Else ......它會正常工作。
謝謝您的幫助
${If} ${Cmd} `MessageBox MB_YESNOCANCEL|MB_ICONEXCLAMATION
"PROGRAM X is already installed. Click YES to remove the installed version
found in C:\Program Files(x86). Click NO to skip uninstall and choose a
different install location (not recommended) or CANCEL to terminate
the installer." IDYES`
MessageBox MB_OK "Yes was clicked"
${ElseIf} {WHAT GOES HERE??}
MessageBox MB_OK "No was clicked"
${Else}
MessageBox MB_OK "Cancel was clicked"
${EndIf}
更新 :我也找到了這個例子,但我不確定${||}
是做什么的,或者它對我有什么幫助。
; ifcmd..||..| and if/unless cmd
StrCpy $R2 ""
${IfCmd} MessageBox MB_YESNO "Please click Yes" IDYES ${||} StrCpy $R2 $R2A ${|}
${Unless} ${Cmd} `MessageBox MB_YESNO|MB_DEFBUTTON2 "Please click No" IDYES`
StrCpy $R2 $R2B
${EndUnless}
${If} $R2 == "AB"
DetailPrint "PASSED IfCmd/If Cmd test"
${Else}
DetailPrint "FAILED IfCmd/If Cmd test"
${EndIf}
以${|}
結尾的行表示如果條件為真,則執行單個指令的if塊:
${IfThen} $Instdir == $Temp ${|} MessageBox mb_ok "$$InstDir equals $$Temp" ${|}
這只是簡寫語法:
${If} $Instdir == $Temp
MessageBox mb_ok "$$InstDir equals $$Temp"
${EndIf}
IfCmd宏在內部使用${IfThen} ${Cmd}
, ${||}
是一個黑客來結束由IfCmd啟動的字符串引用,所以:
${IfCmd} MessageBox MB_YESNO "click yes" IDYES ${||} MessageBox mb_ok choice=IDYES ${|}
是簡寫:
${If} ${Cmd} 'MessageBox MB_YESNO "yes" IDYES' ;notice the quotes here
MessageBox mb_ok choice=IDYES
${EndIf}
你甚至可以混合ifthen和標簽,但這是丑陋的恕我直言:
StrCpy $0 "Cancel"
${IfCmd} MessageBox MB_YESNOCANCEL "Mr. Powers?" IDYES yes IDNO ${||} StrCpy $0 "NO?!" ${|}
MessageBox mb_iconstop $0 ;Cancel or NO
goto end
yes:
MessageBox mb_ok "Yeah baby yeah!"
end:
(最好只使用MessageBox for YESNOCANCEL和ABORTRETRYIGNORE,對於YESNO,OKCANCEL等,為兩個選項執行不同的代碼,使用$ {If} $ {Cmd}'MessageBox ..'.. $ {Else} .. $ {EndIf}語法)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.