Archive: Question about Message Boxes


Question about Message Boxes
  Howdy folks! Brand new here... :)

I am wondering if there is an alternative to being forced to use gotos and labels as the result of buttons in a message box. Instead of using labels I would like to set some flags or something similar. I have been a developer for many years and the thought of using gotos makes me cringe a little bit haha! I am using a MB_YESNOCANCEL message box and once the flags are set I would do some logic on them via LogicLib.nsh.

Thanks for any info!


Try reading the manual and the example scripts supplied with NSIS.

Here is a simple example to get you started:

!include "LogicLib.nsh"


>Name "Demo"
>OutFile demo.exe

RequestExecutionLevel "user"

>ShowInstDetails show

Section default

${If} ${Cmd} `MessageBox MB_YESNO|MB_ICONQUESTION 'Display MAKENSIS help?' IDYES`
DetailPrint "MAKENSIS Help:"
DetailPrint ""
nsExec::ExecToLog '"${NSISDIR}\makensis.exe" /CMDHELP'
DetailPrint ""
${Else}
DetailPrint ""
DetailPrint "User did not request the help listing"
DetailPrint ""
${EndIf}

>SectionEnd
>

Thanks for the info! My apologies, I did look through the manual (but not example scripts) and every mention I could find of MessageBox used labels. I must have missed the part where they work with logical flow statements. I had also googled for hours trying to find this information too so I hope you don't think I was lazy haha :)


I also need this to work with YESNOCANCEL (so 3 buttons), off to searching the manual again and examples I go! Thanks again for pointing me in the right direction.


How about something like this?


"LogicLib.nsh"


>Name "Demo"
>OutFile demo.exe

RequestExecutionLevel "user"

>ShowInstDetails show

Section default

${If} ${
Cmd} `MessageBox MB_YESNOCANCEL|MB_ICONQUESTION 'Display MAKENSIS help?' IDYES`
DetailPrint "MAKENSIS Help:"
DetailPrint ""
nsExec::ExecToLog '"${NSISDIR}\makensis.exe" /CMDHELP'
DetailPrint ""
${ElseIf ${Cmd} `IDNO`}
DetailPrint ""
DetailPrint "User did not request the help listing"
DetailPrint ""
${Else}
{DOSOMETHING ELSE HERE}
${EndIf}

>SectionEnd
>

I find "Windows Grep" useful for searching the example files supplied with NSIS.


Originally posted by pengyou
I find "Windows Grep" useful for searching the example files supplied with NSIS.
That is exactly what I already did. I looked through all instances of "messagebox" and the only ones I found using LogicLib only had 2 choices like your original example.

I also grepped for instances of ${If} and ${Cmd} together to see if they were possibly used with another command other than messagebox, no dice.

I am not lazy, I know how to search for stuff. This isn't my first rodeo =( I may have seen what I needed and not known it was what I needed.

Sorry for the troubles :(

${ElseIf ${Cmd} `IDNO`}
will not compile for several reasons.

Have you bothered to look at the LogicLib.nsi example script? It shows that LogicLib uses ${ElseIf} for the "if ... elseif ... else ... endif" structure.

The ${If} ${Cmd} structure conditionally executes an inline statement, depending on a true value of the provided NSIS function. Your suggestion uses `IDNO` which is not a function.

Originally posted by pengyou
will not compile for several reasons.

Have you bothered to look at the LogicLib.nsi example script? It shows that LogicLib uses ${ElseIf} for the "if ... elseif ... else ... endif" structure.

The ${If} ${Cmd} structure conditionally executes an inline statement, depending on a true value of the provided NSIS function. Your suggestion uses `IDNO` which is not a function.
Yes I have "bothered" to. I hope by now I would have proved my self knowledgeable and competent... I am not someone looking for an easy answer. I had already spent a day looking for a solution to this. I just explained how I even used wingrep to search through all the example file.

My question was never about how to setup the logic structure, I know how to use ${ElseIf} just fine (in general that is). My question is how to use that logic structure specifically with MessageBox YESNOCANCEL.

There are only 2 examples in LogicLib.nsi that reference MessageBox.

  ; 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}
Function ComponentsLeave

; Section flags tests (requires sections.nsh be included)
${Unless} ${SectionIsSelected} ${TESTS}
MessageBox MB_OK "Please select the component"
Abort
${EndIf}
>FunctionEnd
>
Neither of the above reference using an ${ElseIf}

The only example in that script that references ${ElseIf} is the below, and it is just using strings, nothing to do with commands like MessageBox.


  ; if..elseif..else..endif

StrCpy $R1 A
StrCpy $R2 ""
${If} $R1 == A
StrCpy $R2 $R2A
${ElseIf} $R1 == B
StrCpy $R2 $R2B
${ElseUnless} $R1 != C
StrCpy $R2 $R2C
${Else}
StrCpy $R2 $R2D
${EndIf}
${If}$R1 == D
StrCpy $R2 $R2D
${ElseIf} $R1 == A
StrCpy $R2 $R2A
${ElseUnless} $R1 != B
StrCpy $R2 $R2B
${Else}
StrCpy $R2 $R2C
${EndIf}
${If}$R1 == C
StrCpy $R2 $R2C
${ElseIf} $R1 == D
StrCpy $R2 $R2D
${ElseUnless} $R1 != A
StrCpy $R2 $R2A
${Else}
StrCpy $R2 $R2B
${EndIf}
${If}$R1 == B
StrCpy $R2 $R2B
${ElseIf} $R1 == C
StrCpy $R2 $R2C
${ElseUnless} $R1 != D
StrCpy $R2 $R2D
${Else}
StrCpy $R2 $R2A
${EndIf}
${If}$R2 == "$R1$R1$R1$R1"
DetailPrint "PASSED If..ElseIf..Else..EndIf test"
${Else}
DetailPrint "FAILED If..ElseIf..Else..EndIf test"
${EndIf}
What am I missing? Do I have an old example file or something? I promise I am not an idiot! LOL

Originally posted by pengyou
will not compile for several reasons.

Have you bothered to look at the LogicLib.nsi example script? It shows that LogicLib uses ${ElseIf} for the "if ... elseif ... else ... endif" structure.

The ${If} ${Cmd} structure conditionally executes an inline statement, depending on a true value of the provided NSIS function. Your suggestion uses `IDNO` which is not a function.
Also FYI I typoed that, what I had meant was

${ElseIf} ${Cmd} `IDNO` (which still won't work obviously)

Please excuse the slip of the keyboard, I know how to use ${ElseIf}, this isn't my first NSIS script :)

For simplicity, this is exactly what I am trying to figure out... (I can ramble some)

Reference the [WHAT GOES HERE]

   ${If} ${Cmd} `MessageBox MB_YESNOCANCEL|MB_ICONEXCLAMATION "PRORAM 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}

You have to use labels I'm afraid, unless you use nsL (see sticky topic).

Stu