Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 26th March 2011, 04:39   #1
TehMuffinMan
Junior Member
 
Join Date: Mar 2011
Posts: 8
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!
TehMuffinMan is offline   Reply With Quote
Old 26th March 2011, 10:36   #2
pengyou
Major Dude
 
Join Date: Mar 2003
Posts: 569
Try reading the manual and the example scripts supplied with NSIS.

Here is a simple example to get you started:
PHP Code:
!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 
pengyou is offline   Reply With Quote
Old 26th March 2011, 16:03   #3
TehMuffinMan
Junior Member
 
Join Date: Mar 2011
Posts: 8
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
TehMuffinMan is offline   Reply With Quote
Old 26th March 2011, 16:06   #4
TehMuffinMan
Junior Member
 
Join Date: Mar 2011
Posts: 8
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.
TehMuffinMan is offline   Reply With Quote
Old 26th March 2011, 16:25   #5
TehMuffinMan
Junior Member
 
Join Date: Mar 2011
Posts: 8
How about something like this?

PHP Code:
!include "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}
      {DO 
SOMETHING ELSE HERE}
  ${EndIf}

SectionEnd 
TehMuffinMan is offline   Reply With Quote
Old 26th March 2011, 16:27   #6
pengyou
Major Dude
 
Join Date: Mar 2003
Posts: 569
I find "Windows Grep" useful for searching the example files supplied with NSIS.
pengyou is offline   Reply With Quote
Old 26th March 2011, 16:41   #7
TehMuffinMan
Junior Member
 
Join Date: Mar 2011
Posts: 8
Quote:
Originally Posted by pengyou View Post
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
TehMuffinMan is offline   Reply With Quote
Old 26th March 2011, 16:45   #8
pengyou
Major Dude
 
Join Date: Mar 2003
Posts: 569
Quote:
${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.
pengyou is offline   Reply With Quote
Old 26th March 2011, 17:15   #9
TehMuffinMan
Junior Member
 
Join Date: Mar 2011
Posts: 8
Quote:
Originally Posted by pengyou View Post
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.
PHP Code:
  ifcmd..||..| and if/unless cmd
  StrCpy $R2 
""
  
${IfCmdMessageBox 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} 
PHP Code:
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.

PHP Code:
  ; 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
TehMuffinMan is offline   Reply With Quote
Old 26th March 2011, 17:17   #10
TehMuffinMan
Junior Member
 
Join Date: Mar 2011
Posts: 8
Quote:
Originally Posted by pengyou View Post
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
TehMuffinMan is offline   Reply With Quote
Old 26th March 2011, 18:41   #11
TehMuffinMan
Junior Member
 
Join Date: Mar 2011
Posts: 8
For simplicity, this is exactly what I am trying to figure out... (I can ramble some)

Reference the [WHAT GOES HERE]

PHP Code:
    ${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} 
TehMuffinMan is offline   Reply With Quote
Old 26th March 2011, 21:34   #12
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,216
You have to use labels I'm afraid, unless you use nsL (see sticky topic).

Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump