How do I capture the results of a YESNOCANCEL MessageBox without gotos/labels in NSIS installer scripting?

╄→гoц情女王★ 提交于 2019-12-05 13:04:59

A line ending in ${|} indicates a if block that executes a single instruction if the condition is true:

${IfThen} $Instdir == $Temp ${|} MessageBox mb_ok "$$InstDir equals $$Temp" ${|}

This is just shorthand syntax for:

${If} $Instdir == $Temp 
    MessageBox mb_ok "$$InstDir equals $$Temp" 
${EndIf}

The IfCmd macro uses ${IfThen} ${Cmd} internally and ${||} is a hack to end the string quote started by IfCmd, so:

${IfCmd} MessageBox MB_YESNO "click yes" IDYES ${||} MessageBox mb_ok choice=IDYES ${|}

is shorthand for:

${If} ${Cmd} 'MessageBox MB_YESNO "yes" IDYES' ;notice the quotes here
    MessageBox mb_ok choice=IDYES
${EndIf}

You can even mix ifthen and labels, but this is ugly IMHO:

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:

(It is better to just use labels with MessageBox for YESNOCANCEL and ABORTRETRYIGNORE, for YESNO, OKCANCEL etc. that execute different code for both choices, use the ${If} ${Cmd} 'MessageBox ..' .. ${Else} .. ${EndIf} syntax)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!