Old 23rd August 2007, 21:23   #1
johnbm
Junior Member
 
Join Date: Aug 2007
Posts: 2
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
johnbm is offline   Reply With Quote
Old 24th August 2007, 08:36   #2
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
You can add items with LB_ADDSTRING.
code:
${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"


NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 24th August 2007, 16:51   #3
jeffadams78
Junior Member
 
Join Date: Aug 2007
Posts: 15
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...
jeffadams78 is offline   Reply With Quote
Old 24th August 2007, 17:26   #4
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Look up MSDN for LB_ADDSTRING and you will see all the other list box messages available.

Stu
Afrow UK is offline   Reply With Quote
Old 24th August 2007, 17:33   #5
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Send LB_GETCURSEL to get the selected state of an item.
code:
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.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 24th August 2007, 18:39   #6
jeffadams78
Junior Member
 
Join Date: Aug 2007
Posts: 15
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).
jeffadams78 is offline   Reply With Quote
Old 24th August 2007, 18:47   #7
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
It's -1.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 24th August 2007, 18:48   #8
jeffadams78
Junior Member
 
Join Date: Aug 2007
Posts: 15
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!
jeffadams78 is offline   Reply With Quote
Old 24th August 2007, 19:08   #9
jeffadams78
Junior Member
 
Join Date: Aug 2007
Posts: 15
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.
jeffadams78 is offline   Reply With Quote
Old 24th August 2007, 19:10   #10
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Yes, you need System::Call for that. SendMessage alone can't handle strings returning from the message.
code:
System::Call user32::SendMessage(i$MY_LIST_BOX,i${LB_GETTEXT},i$INDEX,t.$0)

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 24th August 2007, 19:21   #11
jeffadams78
Junior Member
 
Join Date: Aug 2007
Posts: 15
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.
jeffadams78 is offline   Reply With Quote
Old 24th August 2007, 20:22   #12
johnbm
Junior Member
 
Join Date: Aug 2007
Posts: 2
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?
johnbm is offline   Reply With Quote
Old 13th February 2008, 10:10   #13
klopfdreh
Junior Member
 
Join Date: Feb 2008
Posts: 34
Hello,

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

PHP Code:
${NSD_CreateListBox0 60 100100""
Pop $ListBox
SendMessage $ListBox 
${LB_ADDSTRING"HELLOOO" 
I defined a Var ListBox and the Compiler compiled it without any errors.

Thanks so far!
klopfdreh is offline   Reply With Quote
Old 13th February 2008, 10:14   #14
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Use "STR:HELLOOO" instead of just "HELLOOO".

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 13th February 2008, 10:20   #15
klopfdreh
Junior Member
 
Join Date: Feb 2008
Posts: 34
Thanks kichik - thats right!

And how can I clear the list?

Edit: Saw it in some CPP Code

PHP Code:
SendMessage $ListBox ${LB_RESETCONTENT0 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

Last edited by klopfdreh; 13th February 2008 at 10:44.
klopfdreh is offline   Reply With Quote
Old 16th December 2008, 19:23   #16
Ivan Andreevich
Junior Member
 
Join Date: Nov 2003
Location: Vancouver, BC
Posts: 48
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
Ivan Andreevich is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump