Archive: Listbox Help


Listbox Help
Hello,

How do I undate a ListBox dynamically ? I want to design a screen with the following fields:
- a directory selection field
- a listbox
- 5 button (add, remove, up, down, clear), where

Add adds an entry to the list (the value from the directory field). Remove removes the selected item from the list, Up/Down move the selected item up/down in the list, and clear clears the list.

Assistance is much appreciated.


-create a installoptions page with the needed controls
-add the notify flag to the buttons
-in the leave function for the page, change the contents of the listbox as needed using the system plugin

(InstallOptionsEx might support updating the items without using the system plugin)


To add items to list box you can do the following:


Var hwnd
!define LB_ADDSTRING 0x180
InstallOptions::initDialog /NOUNLOAD "ioFile.ini"
Pop $hwnd
GetDlgItem $R0 $hwnd 2002 # 2000 + Field # - 1
SendMessage $R0 ${LB_ADDSTRING} "STR:new item"
InstallOptions::display "ioFile.ini"


I might have the second InstallOptions function named wrongly... You'll have to check!

There are other ListBox messages which you'll have to search for either on Google, or MSDN.

-Stu

(InstallOptionsEx might support updating the items without using the system plugin)
Not at this moment.

Thanks for your help. Thanks for the link to the SendMessage function.

How do I get the selected item ... like so ?

GetDlgItem $R1 $hwnd 1204 # 1200 + Field # - 1
SendMessage $R1 ${LB_GETCURSEL} 0 0
Pop $R2

How do I selected an item ...


If anyone has any ideas, please help ...

Thank you.


Use this to select a range of items:

!define LB_SELITEMRANGEEX 0x0183
SendMessage $R0 ${LB_SELITEMRANGEEX} ${From} ${To}

${From} is index to start from, and ${To} is where to stop.
First item would be index 0 (zero based).

Edit: And to un-select all the items again, use:
!define LB_SETSEL 0x0185
SendMessage $R0 ${LB_SETSEL} 0 -1

-Stu


Thanks Stu,

One last question (I think) ...


I guess, to get the selected index, I need to define LB_GETSEL. What I am unsure about is hoe how to get the selected index, the value...

How do I get the value... I guess what I am unclear about is how to get a value from a function, either one that I have definedd or a pre-defined method, like SendMessage.

Thanks again.


The last paramatar for SendMessage can be the return value, and so:

SendMessage $R0 ${LB_GETSEL} 0 0 $R0
$R0 == current selected index

-Stu


Thanks Stu, after posting that message, I tried it and it worked. I didn't get a chance to update ths thread.

I also tried the same approach for LB_GETTEXT (I think) to get the value, but I am getting -1. I wil read up.. but if you done this, I would appreciate if you could post the SendMessage call you used to get the selected value

Thanks a Lot !

Peter


If you want to get the current selected item in an InstallOptions ListBox, just use ReadINIStr, else this should work:

!define LB_GETSEL 0x0187
GetDlgItem $R1 $hwnd 1204 # 1200 + Field # - 1
SendMessage $R1 ${LB_GETSEL} 0 0 $R1

$R1 == selected index

-Stu


Thanks for your help ! Much Appreciated !

Peter


Actually Stu,

If you do not mind answering one more question...

The GETSEL does not see to work .. but the ReadINIStr does... so be it. What I want to do is read all its entries, then traverse them .. and write out each one in a file. I know how to write the file.. i need to do two thigs.

1) Read all the entries

State returns the selected value, ListItems .. no..
Text .. no..

2) Enumerate each "line"



Anyone .. ? thanks !!!


I guess to get all, I can select them all (with SendMessage), and then get them using ReadINI... I will try it.. this is the first thought that came to mind.. and might be a weird way


I'm not sure if that will work. You're adding items with SendMessage but I don't know if the InstallOptions dll will write the added items back to the INI file afterwards...

There's probably a LB_GETRANGE message but I'll have to try it out when I get home (can't do anything here at college!)

-Stu


I'm not sure if that will work. You're adding items with SendMessage but I don't know if the InstallOptions dll will write the added items back to the INI file afterwards...
The items won't (to ListItems) but state items will.

As Stu indicated, the ReadINIStr will read it from the current selected item. If I go next them back, the list is clear again.. need to write it to the ini or store it in a variable.

How do I write it to the ini ReadINIStr ?

Also, how to get all the values ? Whould writing to the ini, then reading ini (ReadStr), state give me the values.. I will try it..

Thanks


To write to the list, use WriteINIStr :)

You can read the list items and then loop through them using this function:
http://nsis.sourceforge.net/archive/...php?pageid=294

Do a loop like so:


Loop:
Push "|" ;divider char
Push $R0 ;input string
Call SplitFirstStrPart
Pop $R1 ;1st part
Pop $R0 ;rest

# ... do stuff with $R1 here! ...

StrCmp $R0 "" 0 Loop ;loop if more list items


-Stu

Hey guys, I'm doing something very similar and wanted to ask some specific questions. I'm using sendmessage to add items to a listbox. On "next", i need to get all the values in the listbox. As deguix said, the added items by sendmessage do not go into the ListItems, so how do I make it go in there, so then I can get it out, and also if I go to next page and then back, the list will still be there?

So, repeating PeterDev's question - how do I get all the values (on "Next")?, what're the specific sendmessage commands to do this? If I can do this, then I can use writeinistr to put it in the ListItems. Any help would be greatly appreciated!!


Originally posted by Afrow UK
To write to the list, use WriteINIStr :)

You can read the list items and then loop through them using this function:
http://nsis.sourceforge.net/archive/...php?pageid=294

Do a loop like so:

Loop:
Push "|" ;divider char
Push $R0 ;input string
Call SplitFirstStrPart
Pop $R1 ;1st part
Pop $R0 ;rest

# ... do stuff with $R1 here! ...

StrCmp $R0 0 Loop ;loop if more list items


-Stu
Hi Afrow UK,

shouldn't it be :

StrCmp $R0 "" 0 Loop ;loop if more list items

instead of what you write :

StrCmp $R0 0 Loop ;loop if more list items

Moreover, i didn't understand how to get all the values from a listbox in installoptions so i can "push $R0" where $R0 is the input string of the listItems. Do i have to use GetDlgItem and SendMessage to do so ?

Yes it should be StrCmp $R0 "" 0 Loop.
Read from the State or ListItems flag with MUI_INSTALLOPTIONS_READ

-Stu


Great Afrow UK, i didn't know ListItems Flag was readable.
It now works as expected.
Thx