- NSIS Discussion
- Warning message when unselecting option
Archive: Warning message when unselecting option
slickgoonie
13th May 2005 17:12 UTC
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.
Afrow UK
13th May 2005 17:17 UTC
!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
deguix
13th May 2005 20:47 UTC
Afrow UK, this code shows the message box whenever the section is not checked, even when checking/unchecking another section.
Afrow UK
13th May 2005 21:21 UTC
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
restools
15th May 2005 18:09 UTC
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
deguix
15th May 2005 19:24 UTC
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.
restools
16th May 2005 05:09 UTC
????
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
;--------------------------------
deguix
16th May 2005 06:59 UTC
SF_SELECTED, whatever...
restools
16th May 2005 11:35 UTC
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
slickgoonie
18th May 2005 20:13 UTC
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.
playwin2
18th May 2005 21:24 UTC
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.
slickgoonie
18th May 2005 22:17 UTC
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.
deguix
19th May 2005 03:48 UTC
Something else is wrong in resttools' code. This line is wrong:
SectionGetFlags SEC1 $0
and it should be:
SectionGetFlags ${SEC1} $0
Afrow UK
19th May 2005 18:52 UTC
Just use my code. I've tested it :p
-Stu
slickgoonie
27th May 2005 19:17 UTC
Thanks it works!