Skip to content
⌘ NSIS Forum Archive

Contents of a Listbox

6 posts

davidnewcomb#

Contents of a Listbox

I have trawled the forums and been unable to find an answer. There are loads of threads talking about Listboxes, but almost no documentation about manipulating them on the main site 🙁

I have been populating a ListBox and I want to read out what is in there. I have read through:



which talks about listbox controls. It mentions getting selected indexes, counting how many items there are etc, but surprisingly there does not seem to be a "what is the text at index n" question.

I am stuck! Is there any (simpler) way?
davidnewcomb#
I thought so, but it is not producing the response I expect:
I popuplate the list box

Then in <custom>Leave

!insertmacro MUI_INSTALLOPTIONS_READ $0 "ZoneConfiguration" "${CP_ZONE__LIST}" "HWND"

SendMessage $0 ${LB_GETTEXT} 0 $R0
MessageBox MB_OK "ListItems0->|$R0|"
SendMessage $0 ${LB_GETTEXT} 1 $R0
MessageBox MB_OK "ListItems1->|$R0|"
SendMessage $0 ${LB_GETTEXT} 2 $R0
MessageBox MB_OK "ListItems2->|$R0|"

The popup always displays the last entry in the list box!

How can I get all the entries in the list box irrespective of whether they are selected or not.
Joel#
Try this:
!insertmacro MUI_INSTALLOPTIONS_READ $0 "ZoneConfiguration" "${CP_ZONE__LIST}" "HWND"
System::Call "user32::SendMessageA(i r0, i ${LB_GETCOUNT}, i 0, i 0) i .r1"
StrCpy $2 0
${Do}
System::Call "user32::SendMessageA(i r0, i ${LB_GETTEXT}, i r2, t .r3) i .r1"
MessageBox MB_OK "Item: $2 is $3"
IntOp $2 $2 + 1
${LoopUntil} $2 = $1
MessageBox MB_OK "Done!" 
I used !include "LogicLib.nsh" and works for me great 🙂
davidnewcomb#
Red Wine: ListItems always returns empty
Joel: Thanks LB_GETCOUNT returns the size of the the Listbox and not the number of entries it contains.

I found that this worked better:


StrCpy $2 0
loop_start:
System::Call "user32::SendMessageA(i r0, i ${LB_GETTEXT}, i r2, t .r3) i .r1"
; MessageBox MB_OK "Item: $2 is $3"
MessageBox MB_OK "Item: $2 is |$3|"
StrCmp $3 "" realend
!insertmacro WriteZoneInfo "${TMPDIR}\${TMP_ZONES_FILE}" $3
IntOp $2 $2 + 1
goto loop_start

realend:

Happy now!