Archive: nsDialogs - using ${NSD_CreateListBox}


nsDialogs - using ${NSD_CreateListBox}
  I'm interested in using a listbox in nsDialogs. It's unclear to me from the documentation I have seen though how one can populate the listbox and once this is done how one captures the selection made in the listbox.

If I use the code:

${NSD_CreateListBox} 100 40 20% 12u "sample entry"

it will create a blank listbox.

Would anyone be able to clarify this for me?

Thanks, John


You can add items with LB_ADDSTRING.

${NSD_CreateListBox} 100 40 20% 12u ""
Pop $ListBox
SendMessage $ListBox ${LB_ADDSTRING} 0 "STR:Simple entry"
SendMessage $ListBox ${LB_ADDSTRING} 0 "STR:Another entry"
SendMessage $ListBox ${LB_ADDSTRING} 0 "STR:Blah"

How do you get the selection from the list box? And can you have a change function?

GetFunctionAddress $0 OnMyListBoxChange
nsDialogs::OnChange /NOUNLOAD $MY_LIST_BOX $0

Doesn't seem to work...


Look up MSDN for LB_ADDSTRING and you will see all the other list box messages available.

Stu


Send LB_GETCURSEL to get the selected state of an item.

SendMessage $MY_LIST_BOX ${LB_GETCURSEL} 0 0 $0
# $0 will not be zero if the item is selected
List box notification is only sent when the LBS_NOTIFY style is used. I have added it to the next version of nsDialogs.nsh. For the current version, you can manually create the list box when the desired flags or add |${LBS_NOTIFY} to the definition of __NSD_ListBox_STYLE in nsDialogs.nsh.

LB_GETCURSEL returns the index or "LB_ERR" if no line is selected. Any idea what LB_ERR is? -1? You don't appear to have it defined in nsDialogs.nsh. The index is supposedly 0-based, so 0 is valid (first line).


It's -1.


You beat me to the post ;). LB_ERR = -1... because that's what I get back every time I send the LB_GETCURSEL message. Any idea why that would be?------

Nevermind, it was a bug in my code, I get the correct value from the message I wasn't copying it into the right variable.

Manually creating the list box with LBS_NOTIFY worked great though as far as getting OnChange notifications.

Thanks!


Any reason why LB_GETTEXT wouldn't work? I'm trying to get the text that the user selected, and I think this should work:

SendMessage $MY_LIST_BOX ${LB_GETCURSEL} 0 0 $0
${IF} $0 >= 0
IntOp $1 $0 + 0;
SendMessage $MY_LIST_BOX ${LB_GETTEXT} $1 $0 $2
MessageBox MB_OK '0: $0, 1: $1, 2: $2'
${ENDIF}

I always get back: $0 is the correct index (from the first SendMessage, the second one fails and doesn't write to it), $1 is the same (since I copied $0 into it), and $2 is LB_ERR, which according to the MSDN means that I passed an invalid index... but it is valid.


Yes, you need System::Call for that. SendMessage alone can't handle strings returning from the message.

System::Call user32::SendMessage(i$MY_LIST_BOX,i${LB_GETTEXT},i$INDEX,t.$0)

Hmm, that still didn't work. I've actually changed my mind and decided that the index is fine for my purposes, but thanks for your help.


kichik thanks for your help, that worked well and it's pointed me in the right direction on a number of things. I'm now trying to create a combobox with a dropdown style.

${NSD_CreateComboBox} 200 20 20% 59u ""
Pop $ComboBox
SendMessage $ComboBox ${CB_ADDSTRING} 0 "STR:First Entry"
SendMessage $ComboBox ${CB_ADDSTRING} 0 "STR:Second Entry"
SendMessage $ComboBox ${CB_ADDSTRING} 0 "STR:Third Entry"

I know that I need to use CBS_DROPDOWN to set the style and I expect that I add this as an extra parameter to

${NSD_CreateComboBox} 200 20 20% 59u ""

but I'm not sure of the syntax.

I believe one may also be able to do this by using CreateWindow. Does anyone know how this is done?


Hello,

I saw that thread about ListBox and I tried it by myself, but this codesnippet below doesn't work for me:

${NSD_CreateListBox} 0 60 100% 100% ""

>Pop $ListBox
SendMessage $ListBox${LB_ADDSTRING} 0 "HELLOOO"
I defined a Var ListBox and the Compiler compiled it without any errors. :weird:

Thanks so far!

Use "STR:HELLOOO" instead of just "HELLOOO".


Thanks kichik - thats right!

And how can I clear the list?

Edit: Saw it in some CPP Code


SendMessage $ListBox ${LB_RESETCONTENT} 0 0 

>
Thanks a lot!

P.S.:

May you are able to help me with DialogsEx? I have another post here with a problem which hasn't been solved yet:

Topic:
Custom Page with FileSelect-Button

URL:
http://forums.winamp.com/showthread....hreadid=286733

Ah, this was something I was looking for.

I am using an nsDialogs DropList, so my code is slightly different. Here it is for reference. It's combo box commands.

Clear droplist:
SendMessage $DropList ${CB_RESETCONTENT} 0 0

Add entry ($1) to droplist:
SendMessage $DropList ${CB_ADDSTRING} 0 "STR:$1"

Select entry ($1) in the droplist:
SendMessage $DropList ${CB_SELECTSTRING} 0 "STR:$1"

Ivan