;--------------------------------
;Include Modern UI

  !define LOGICLIB_SECTIONCMP

  !include "MUI.nsh"
  !include "logiclib.nsh"
  !include "sections.nsh"

;--------------------------------
;General

  ;Name and file
  Name "Test"
  OutFile "test.exe"
  
;--------------------------------
;Pages

  !insertmacro MUI_PAGE_COMPONENTS
  !insertmacro MUI_PAGE_INSTFILES

Section A secA
SectionEnd

Section /o B secB
SectionEnd

Section C secC
SectionEnd

Section D secD
SectionEnd

!define SECTIONCOUNT 3 ; total - 1

;--------------------------------
;Count all selected sections
!macro CountSections VAR
  StrCpy ${VAR} 0
  ${For} $R0 0 ${SECTIONCOUNT}
    ${If} ${SectionIsSelected} $R0
		  IntOp ${VAR} ${VAR} + $R0
		${EndIf}
  ${Next}
!macroend

Function .onSelChange
  ; count all selected sections to compare
	!insertmacro CountSections $R1

  IntOp $R3 $R2 - $R1
	${If} $R3 < 0
	  IntOp $R3 $R3 * -1
	${EndIf}

  SectionGetText $R3 $R4
	
	MessageBox MB_OK "Section '$R4' ($R3) has been changed."

  ;save number for later comparison
	StrCpy $R2 $R1
	
FunctionEnd

Function .onInit
  ; count initial selected sections
	!insertmacro CountSections $R2
FunctionEnd

;--------------------------------
;Languages
 
  !insertmacro MUI_LANGUAGE "English"

