Archive: Warning message when unselecting option


Warning message when unselecting option
Hi:

Here what i'd like to do:

On the components page, there is an option that whenever the user unselect it, i want to display a warning message warning the user about the importance of that package. So how can i do that?? i've been browsing around and i couln't find anything that let me check if a component has been unselected or not...

thanks.


!include Sections.nsh

Section "A section" SECID
SectionEnd

Function .onSelChange

SectionGetFlags ${SECID} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
StrCmp $R0 ${SF_SELECTED} +2
MessageBox MB_OK|MB_ICONEXCLAMATION "Unchecked #${SECID}!"

FunctionEnd


-Stu

Afrow UK, this code shows the message box whenever the section is not checked, even when checking/unchecking another section.


Sorry, fixed:


!include Sections.nsh

Section "A section" SECID
SectionEnd

Section "A sectioaan" SECIDa
SectionEnd

Var SectionVar

Function .onInit
StrCpy $SectionVar ${SF_SELECTED}
FunctionEnd

Function .onSelChange

SectionGetFlags ${SECID} $R0
IntOp $R0 $R0 & ${SF_SELECTED}

StrCmp $R0 $SectionVar +4
StrCpy $SectionVar $R0

StrCmp $R0 ${SF_SELECTED} +2
MessageBox MB_OK|MB_ICONEXCLAMATION "Unchecked #${SECID}!"

FunctionEnd


-Stu

try this script~~

!include "MUI.nsh"

Name "test"
OutFile "Setup.exe"

!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES

!insertmacro MUI_LANGUAGE "english"

!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS

Var cbState

Function .onInit
IntFmt $cbState "%d" 1
FunctionEnd

Section
"section a" SEC1
SectionEnd

Section
"section b" SEC2
SectionEnd

Function
.onSelChange
Push $0
SectionGetFlags SEC1 $0
IntCmp $0 $cbState +4
IntFmt $cbState "%d" $0
IntCmp $0 1 +2
MessageBox MB_OK|MB_ICONEXCLAMATION "SEC1 Unchecked"
Pop $0
FunctionEnd



You cannot do that way. Sometimes, the SF_CHECKED flag has other flags with it, and that wouldn't work. An hexadecimal number allows setting flags without interferance from the existance of other flags. That's why the number returned by SectionGetFlags is an hexadecimal number.


????
SF_SELECTED = 1

;--------------------------------

; Generic section defines

!define SF_SELECTED 1 ; <<<---------- ????????
!define SF_SECGRP 2
!define SF_SUBSEC 2 # deprecated
!define SF_SECGRPEND 4
!define SF_SUBSECEND 4 # deprecated
!define SF_BOLD 8
!define SF_RO 16
!define SF_EXPAND 32
!define SF_PSELECTED 64 # internal
!define SF_TOGGLED 128 # internal
!define SF_NAMECHG 256 # internal

!define SECTION_OFF 0xFFFFFFFE

;--------------------------------


SF_SELECTED, whatever...


oh~ I see your point.

!include "MUI.nsh"
!include "Sections.nsh"

Name "test"
OutFile "Setup.exe"

!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES

!insertmacro MUI_LANGUAGE "english"

!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS

Var cbState

Function .onInit
IntFmt $cbState "%x" ${SF_SELECTED}
FunctionEnd

Section
"section a" SEC1
SectionEnd

Section
"section b" SEC2
SectionEnd

Function
.onSelChange
Push $0
SectionGetFlags SEC1 $0
IntOp $0 $0 & ${SF_SELECTED} # <<<<-------- add
IntCmp $0 $cbState +4
IntFmt $cbState "%d" $0
IntCmp $0 ${SF_SELECTED} +2
MessageBox MB_OK|MB_ICONEXCLAMATION "SEC1 Unchecked"
Pop $0
FunctionEnd


Thanks to everyone who helped out with this, now i have one more question...could someone explain me the reason for all those "magic numbers" 2,4, etc etc, i dont know why you guys add sometimes 2 or 4...

thanks.


Those 4 and 2 are jumps.

For example:

IntCmp $0 $cbState +4


-- this line means that if the vars. you are comp. is same then goto line 4.(i.e. skip the next 3 lines.)

See the help file for relative jumps.

oh ok, I'm sorry if i sound dumb but..how do i make it so the message will be displayed when unselection the second section?? i tried changing sec1 for sec2, didnt work.

thanks.


Something else is wrong in resttools' code. This line is wrong:

SectionGetFlags SEC1 $0

and it should be:
SectionGetFlags ${SEC1} $0

Just use my code. I've tested it :p

-Stu


Thanks it works!