Skip to content
⌘ NSIS Forum Archive

Adding a check all / uncheck all

6 posts

ggarra13#

Adding a check all / uncheck all

I inherited code that lists a bunch of options and allows the user to select them:


!include nsDialogs.nsh
!include WinMessages.nsh
!ifndef LVM_GETITEMTEXT
!define /math LVM_GETITEMTEXTA ${LVM_FIRST} + 45
!define /math LVM_GETITEMTEXTW ${LVM_FIRST} + 115
${_NSIS_DEFAW} LVM_GETITEMTEXT
!endif
Var hListCtl
Page Custom LVPageCreate LVPageLeave

Function AddCheckedListViewItemWith1SubItem
System::Store S
Pop $4
Pop $3
Pop $2
Pop $1
System::Call '*(i ${LVIF_TEXT},i 0x7fffffff,i 0,i,&i${NSIS_PTR_SIZE},tr2,i,i,p)p.r9'
SendMessage $1 ${LVM_INSERTITEM} "" $9 $0
System::Call '*$9(i${LVIF_STATE},i,i,i0x2000,&i${NSIS_PTR_SIZE} ${LVIS_STATEIMAGEMASK},p,i,i,p)'
IntCmpU $4 0 +2
SendMessage $1 ${LVM_SETITEMSTATE} $0 $9 $8
System::Call '*$9(i,i 0x7fffffff,i 1,i,i,tr3,i,i,p)'
SendMessage $1 ${LVM_SETITEMTEXT} $0 $9
System::Free $9
System::Store L
FunctionEnd

!macro AddCheckedListViewItemWith1SubItem hLV txt sub1 checked
Push ${hLV}
Push "${txt}"
Push "${sub1}"
Push "${checked}"
Call AddCheckedListViewItemWith1SubItem
!macroend

Function LVPageCreate
nsDialogs::Create 1018
Pop $0

${NSD_CreateLabel} 0 0 100% 12u "File associations for mrViewer"

nsDialogs::CreateControl "SysListView32" ${DEFAULT_STYLES}|${WS_TABSTOP}|${WS_VSCROLL}|${LVS_REPORT} ${WS_EX_WINDOWEDGE}|${WS_EX_CLIENTEDGE} 0 20 100% 90% ""
Pop $hListCtl
IntOp $0 ${LVS_EX_FULLROWSELECT} | ${LVS_EX_CHECKBOXES}
SendMessage $hListCtl ${LVM_SETEXTENDEDLISTVIEWSTYLE} 0 $0
System::Call '*(i${LVCF_TEXT}|${LVCF_SUBITEM},i,i,t "Extension",i,i 0)p.r9'
SendMessage $hListCtl ${LVM_INSERTCOLUMN} 0x7fffffff $9
System::Call '*$9(i,i,i,t "Description",i,i 1)'
SendMessage $hListCtl ${LVM_INSERTCOLUMN} 0x7fffffff $9
System::Free $9

# ...the options...

!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".tiff" "TIFF file" 1
!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".tga" "Targa file" 1
!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".bmp" "Windows/OS2 Bitmap" 1
# ...etc...

SendMessage $hListCtl ${LVM_SETCOLUMNWIDTH} 0 -1
SendMessage $hListCtl ${LVM_SETCOLUMNWIDTH} 1 -1
System::Call 'USER32::PostMessage(p $hwndparent, i ${WM_NEXTDLGCTL}, p $hListCtl, i1)'
nsDialogs::Show
FunctionEnd

# LVLeavePage not shown
I would like to have a checkin button and function that toggles on/off all the listed items.

Can someone help me write it?
JasonFriday13#
I guess you could do this with a components page and relevant sections instead:

!include "Sections.nsh"
RequestExecutionLevel user
ShowInstDetails show
Page Components
Page InstFiles
SectionGroup "File associations for mrViewer" SecAssoc
Section ".tiff (TIFF file)"
  DetailPrint ".tiff (TIFF file)"
SectionEnd
Section ".tga (Targa file)"
  DetailPrint ".tga (Targa file)"
SectionEnd
Section ".bmp (Windows/OS2 Bitmap)"
  DetailPrint ".bmp (Windows/OS2 Bitmap)"
SectionEnd
SectionGroupEnd
Function .oninit
  SectionGetFlags ${SecAssoc} $0
  IntOp $0 $0 | ${SF_EXPAND}
  SectionSetFlags ${SecAssoc} $0
FunctionEnd 
Anders#
!macro LVCheckAll hLV tempvar
System::Call '*(i ${LVIF_STATE},i,i 0,i0x2000,&i${NSIS_PTR_SIZE} ${LVIS_STATEIMAGEMASK},p0,i0,i,p)p.s'
Pop ${tempvar}
SendMessage ${hLV} ${LVM_SETITEMSTATE} -1 ${tempvar}
System::Free ${tempvar}
!macroend
!macro LVUncheckAll hLV tempvar
System::Call '*(i ${LVIF_STATE},i,i 0,i0x1000,&i${NSIS_PTR_SIZE} ${LVIS_STATEIMAGEMASK},p0,i0,i,p)p.s'
Pop ${tempvar}
SendMessage ${hLV} ${LVM_SETITEMSTATE} -1 ${tempvar}
System::Free ${tempvar}
!macroend
...
!insertmacro LVCheckAll $hListCtl $0 
ggarra13#
Adding a check all / uncheck all

I have an installer written by someone else that has a number of checkboxes. I would like to add another checkbox to turn on/off all other checkboxes, but don't know how. Can someone help me?

Here's the code for the current implementation:


!include nsDialogs.nsh
!include WinMessages.nsh


!ifndef LVM_GETITEMTEXT
!define /math LVM_GETITEMTEXTA ${LVM_FIRST} + 45
!define /math LVM_GETITEMTEXTW ${LVM_FIRST} + 115
${_NSIS_DEFAW} LVM_GETITEMTEXT
!endif
Var hListCtl
Page Custom LVPageCreate LVPageLeave


Function AddCheckedListViewItemWith1SubItem
System::Store S
Pop $4
Pop $3
Pop $2
Pop $1
System::Call '*(i ${LVIF_TEXT},i 0x7fffffff,i 0,i,&i${NSIS_PTR_SIZE},tr2,i,i,p)p.r9'
SendMessage $1 ${LVM_INSERTITEM} "" $9 $0
System::Call '*$9(i${LVIF_STATE},i,i,i0x2000,&i${NSIS_PTR_SIZE} ${LVIS_STATEIMAGEMASK},p,i,i,p)'
IntCmpU $4 0 +2
SendMessage $1 ${LVM_SETITEMSTATE} $0 $9 $8
System::Call '*$9(i,i 0x7fffffff,i 1,i,i,tr3,i,i,p)'
SendMessage $1 ${LVM_SETITEMTEXT} $0 $9
System::Free $9
System::Store L
FunctionEnd

!macro AddCheckedListViewItemWith1SubItem hLV txt sub1 checked
Push ${hLV}
Push "${txt}"
Push "${sub1}"
Push "${checked}"
Call AddCheckedListViewItemWith1SubItem
!macroend

Function LVPageCreate
nsDialogs::Create 1018
Pop $0

${NSD_CreateLabel} 0 0 100% 12u "File associations for mrViewer"

nsDialogs::CreateControl "SysListView32" ${DEFAULT_STYLES}|${WS_TABSTOP}|${WS_VSCROLL}|${LVS_REPORT} ${WS_EX_WINDOWEDGE}|${WS_EX_CLIENTEDGE} 0 20 100% 90% ""
Pop $hListCtl
IntOp $0 ${LVS_EX_FULLROWSELECT} | ${LVS_EX_CHECKBOXES}
SendMessage $hListCtl ${LVM_SETEXTENDEDLISTVIEWSTYLE} 0 $0
System::Call '*(i${LVCF_TEXT}|${LVCF_SUBITEM},i,i,t "Extension",i,i 0)p.r9'
SendMessage $hListCtl ${LVM_INSERTCOLUMN} 0x7fffffff $9
System::Call '*$9(i,i,i,t "Description",i,i 1)'
SendMessage $hListCtl ${LVM_INSERTCOLUMN} 0x7fffffff $9
System::Free $9
!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".au" "Solaris Audio file" 1
!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".bit" "mental ray Bitmap" 1
!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".bmp" "Windows/OS2 Bitmap" 1
!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".braw" "Blackmagic RAW Movie" 1
!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".cin" "Kodak Cineon" 1
!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".ct" "mental ray contour" 1
!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".dds" "DirectDraw Surface" 1
!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".dib" "Windows Device Independent Bitmap" 1


SendMessage $hListCtl ${LVM_SETCOLUMNWIDTH} 0 -1
SendMessage $hListCtl ${LVM_SETCOLUMNWIDTH} 1 -1
System::Call 'USER32::PostMessage(p $hwndparent, i ${WM_NEXTDLGCTL}, p $hListCtl, i1)'
nsDialogs::Show
FunctionEnd


Function LVPageLeave
System::Call '*(&t${NSIS_MAX_STRLEN},i)p.r8'
System::Call '*(i ${LVIF_TEXT},i,i 0,i,&i${NSIS_PTR_SIZE},pr8,i${NSIS_MAX_STRLEN},i,p)p.r9'
SendMessage $hListCtl ${LVM_GETITEMCOUNT} "" "" $1
StrCpy $0 0
${DoWhile} $0 < $1
SendMessage $hListCtl ${LVM_GETITEMSTATE} $0 ${LVIS_STATEIMAGEMASK} $2
IntOp $2 $2 & 0x2000
${If} $2 <> 0
SendMessage $hListCtl ${LVM_GETITEMTEXT} $0 $9 $2
System::Call '*$8(&t${NSIS_MAX_STRLEN}.r7)'
WriteRegStr HKCR '$7' '' 'mrViewer'
WriteINIStr '$INSTDIR\\fileext.ini' ext '$7' 1
${EndIf}
IntOp $0 $0 + 1
${Loop}
System::Free $8
System::Free $9
FunctionEnd


ggarra13#
Anders,

Thank you for answering. However, your code does not seem to work. There's no "check all" / "uncheck all" buttons in the gui when I add your code.
Anders#
Originally Posted by ggarra13 View Post
Thank you for answering. However, your code does not seem to work. There's no "check all" / "uncheck all" buttons in the gui when I add your code.
I know it does not add the button, you have to add the button yourself with nsDialogs. The button onclick handler should insert the check/uncheck macros.