Sorting Components

From NSIS Wiki

Author: KiCHiK (talk, contrib)


The following script shows how to sort components in the components page under a certain group. It was written for theAdib in the forums. His intention was to keep sections sorted for all available languages.

!define TVGN_ROOT        0
!define TVGN_NEXT        1
!define TVGN_NEXTVISIBLE 6
 
!define TVIF_TEXT   1
 
!define TVM_GETNEXTITEM  4362
!define TVM_GETITEMA     4364
!define TVM_GETITEMW     4414
!define TVM_SORTCHILDREN 4371
 
!define TVITEM '(i, i, i, i, i, i, i, i, i, i)'
 
!ifdef NSIS_UNICODE
    !define TVM_GETITEM ${TVM_GETITEMW}
!else
    !define TVM_GETITEM ${TVM_GETITEMA}
!endif
 
 
Page components "" compShow
Page instfiles
 
XPStyle on
 
Name "test"
OutFile "test.exe"
 
Section ztest
SectionEnd
 
SectionGroup /e test
 
Section c
SectionEnd
 
Section b
SectionEnd
 
Section a
SectionEnd
 
SectionGroupEnd
 
Function compShow
 
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $0 1032
 
SendMessage $0 ${TVM_GETNEXTITEM} ${TVGN_ROOT} 0 $1
 
System::Alloc ${NSIS_MAX_STRLEN}
Pop $2
 
loop:
	System::Call '*${TVITEM}(${TVIF_TEXT}, r1,,, r2, ${NSIS_MAX_STRLEN},,,,) i .r3'
	SendMessage $0 ${TVM_GETITEM} 0 $3
	System::Call '*$2(&t${NSIS_MAX_STRLEN} .r4)'
	StrCmp $4 "test" 0 +2 ### CHANGE ME
		Goto found
 
	SendMessage $0 ${TVM_GETNEXTITEM} ${TVGN_NEXTVISIBLE} $1 $1
	StrCmp 0 $1 done loop
 
found:
	SendMessage $0 ${TVM_SORTCHILDREN} 0 $1
	# recursive - SendMessage $0 ${TVM_SORTCHILDREN} 1 $1
 
done:
 
System::Free $2
System::Free $3
 
FunctionEnd
Personal tools
donate
ads