hey,
well i have a listbox set up,
but i cant get any text into it,
how do i put text into it?
i hve read all of the posts about this and they seem to be for windows, and im using a dialog.

thanks,
njkt
Posted on 2003-08-11 13:05:48 by njkt809
Dialog boxes are windows too! :) The dialog box ID you pass to CreateDialogParam is a resource id, that is a number used to identify the resource with data to create a dialog box. The dialog box itself is a window, you get it in the hWnd param in your dialog procedure, or as the return value of CreateDialogParam, as well.
Posted on 2003-08-11 15:25:14 by QvasiModo
so it would be like this?

invoke SendMessage,LBHandle,LB_INSERTSTRING,offset IDC_MONLIST,offset namep
Posted on 2003-08-11 15:34:12 by njkt809
From Win32.hlp:
LB_INSERTSTRING
wParam = (WPARAM) index; // item index
lParam = (LPARAM) (LPCTSTR) lpsz; // address of string to insert

So it would be:


invoke SendMessage,LBHandle,LB_INSERTSTRING,iItemIndex,offset namep

Where iItemIndex is the index to the new item. Use 0 to insert at the top of the list, and -1 to append at the end of the list.
Posted on 2003-08-11 15:48:10 by QvasiModo
it doesnt work still,
ok i have the string
Text db "1. somthing",0
db "2. somthing else",0

and the code

invoke SendMessage,hInstance,LB_TEXT,-1,offset IDC_MONLIST

it doesnt show anything in the listbox

thanks,
njkt
Posted on 2003-08-11 16:30:11 by njkt809
ahm, hInstance sounds rather suspicious for a window handle. Have you got it by GetDlgItem function?
Posted on 2003-08-11 16:55:55 by japheth
i think not,
that was a test one i was testing by accident
i think it should be

invoke SendMessage,hWin,LB_TEXT,-1,offset IDC_MONLIST

but i have no source for a list box, the info i have doesnt have any mention of a list box.

thanks,
njkt
Posted on 2003-08-11 17:07:44 by njkt809
Go back to using the LBHandle and a name pointer:

invoke SendMessage, LBHandle, LB_INSERTSTRING, -1, namep

You can get the LBHandle with:

invoke GetDlgItem, hDlg, IDC_ListboxControl
mov LBHandle, eax

where IDC_ListboxControl is the control ID for the desired list box.
Posted on 2003-08-11 17:42:09 by tenkey
hey,
well it still doesnt work,
here is what i got

invoke GetDlgItem, hDlg, IDC_MONLIST
mov LBHandle, eax
mov esi,LBHandle
mov edi,offset LB_TEXT
xor ebx,ebx
invoke SendMessage,esi,LB_INSERTSTRING,ebx,edi

still doesnt work,
are there any examples that use a dialog?

thanks,
njkt
Posted on 2003-08-11 18:14:44 by njkt809
hey,
well heres the source, i think it will make more sence than my bad explanations. (and spelling)



thanks,
njkt
Posted on 2003-08-12 01:31:54 by njkt809
Hi njkt809,

The download Mini MP3 Player "mp3demo.zip" from the Source Code section on Iczelion's site:

http://spiff.tripnet.se/

might just be a wealth of information for you...

http://spiff.tripnet.se/~iczelion/files/mp3demo.zip

Lots of other useful code there too.
Posted on 2003-08-12 07:59:28 by gscundiff
Hi njkt809,

If this is what you are talking about, then "text" should be "Offset text". Also instead of "mov LBHandle, ebx" you should have "mov LBHandle, eax".

;#############################################################################
; Help, Credits, About not much use..hahaha (it was a bugger in the beginning)
;#############################################################################
DlgProc proc hWin:HWND,iMsg:UINT,wParam:WPARAM,lParam:LPARAM

mov eax, iMsg
.if eax==WM_INITDIALOG
invoke GetDlgItem,hDlg,IDC_MONLIST
mov LBHandle, ebx
invoke SendMessage, LBHandle, LB_INSERTSTRING, -1, text

Also, I guess that the listbox is not in the above dialog (because you use hDlg instead of hWin). Is hDlg loaded ? (It would help if you could send the command line you use to build so that we can help more).

Regards,

akyprian
Posted on 2003-08-12 09:09:32 by akyprian
hey,
thanks for the source,
no that was just something i was mesing with,
the list box is in ArenaProc

im going to look at the mini mp3 player thanks,

njkt
Posted on 2003-08-12 09:30:16 by njkt809
How about this?


; Arena
;#######################################################################
ArenaProc proc hWin:HWND,iMsg:UINT,wParam:WPARAM,lParam:LPARAM

mov eax, iMsg
.if eax==WM_INITDIALOG

invoke GetDlgItem, hWin
invoke SendMessage, eax, LB_ADDSTRING, 0, offset text
invoke SendMessage, hWin, LB_SETITEMDATA, eax, IDC_MONLIST

Try it and tell me if it works... :)
Posted on 2003-08-12 10:18:18 by QvasiModo
AHHHHHH finally,
this lil bugger has been the bain of my coding for 4 days now.:tongue:

but how come i can only add one item? how do i use multiple items?

now how do i tell if the item is selected and then do actions based on the choice?


thanks,
njkt
Posted on 2003-08-12 10:22:07 by njkt809
I don't know of any message to add several listbox items at once, so you must send several LB_ADDSTRING messages. Hint: use loops ;)
The LB_GETCURSEL message retrieves the current selection.
From WIN32.HLP:

LB_GETCURSEL
wParam = 0; // not used; must be zero
lParam = 0; // not used; must be zero

Return Values

In a single-selection list box, the return value is the zero-based index of the currently selected item. If there is no selection, the return value is LB_ERR.

Remarks

Do not send this message to a multiple-selection list box.
To retrieve the indexes of the selected items in a multiple-selection list box, use the LB_GETSELITEMS message. To determine whether the item that has the focus rectangle in a multiple selection list box is selected, use the LB_GETSEL message.
If sent to a multiple-selection list box, LB_GETCURSEL returns the index of the item that has the focus rectangle. If no items are selected, it returns zero.


LB_GETSELITEMS
wParam = (WPARAM) cItems; // maximum number of items
lParam = (LPARAM) (LPINT) lpnItems; // address of buffer


Parameters

cItems

Value of wParam. Specifies the maximum number of selected items whose item numbers are to be placed in the buffer.
Windows 95: The wParam parameter is limited to 16-bit values. This means list boxes cannot contain more than 32,767 items. Although the number of items is restricted, the total size in bytes of the items in a listbox is limited only by available memory.

lpnItems

Value of lParam. Points to a buffer large enough for the number of integers specified by the cItems parameter.



Return Values

The return value is the number of items placed in the buffer. If the list box is a single-selection list box, the return value is LB_ERR.



LB_GETSELCOUNT
wParam = 0; // not used; must be zero
lParam = 0; // not used; must be zero


Return Values

The return value is the count of selected items in the list box. If the list box is a single-selection list box, the return value is LB_ERR.

My feeling is you need a single selection listbox, so the first message will work for you. Remember to set the listbox style correctly. Also you might want to set the initial selection after adding the items (use the first one for single selection listbox):
From WIN32.HLP:

LB_SETCURSEL
wParam = (WPARAM) index; // item index
lParam = 0; // not used; must be zero


LB_SETSEL
wParam = (WPARAM) (BOOL) fSelect; // selection flag
lParam = (LPARAM) (UINT) index; // item index


Parameters

fSelect

Value of wParam. Specifies how to set the selection. If the fSelect parameter is TRUE, the string is selected and highlighted; if fSelect is FALSE, the highlight is removed and the string is no longer selected.

index

Value of lParam. Specifies the zero-based index of the string to set. If index is -1, the selection is added to or removed from all strings, depending on the value of fSelect.

Have fun ;)
Posted on 2003-08-12 10:42:37 by QvasiModo
To add multiple items to a listbox I wrote this macro, it takes an array of items and adds them all. The items are in the format:

Array db "item1",0,"item2",0,"item3",0,0 <--Note the extra zero terminator

to use it there is no invoke just:
LB_SetContent hListBox,OFFSET Array
LB_SetContent MACRO hControl, pList

push edi
push esi
mov esi,pList
push esi
@@:
add esi,1
mov al,[esi]
cmp al,0
jne @B
add esi,1
pop edi
invoke SendMessage,hControl,LB_ADDSTRING,0,edi
mov cl,[esi]
cmp cl,0
je @F
push esi
jmp @B
@@:
pop esi
pop edi
ENDM


This one will do combo boxes:
CB_SetContent MACRO hControl, pList

push edi
push esi
mov esi,pList
push esi
@@:
add esi,1
mov al,[esi]
cmp al,0
jne @B
add esi,1
pop edi
invoke SendMessage,hControl,CB_ADDSTRING,0,edi
mov cl,[esi]
cmp cl,0
je @F
push esi
jmp @B
@@:
pop esi
pop edi
ENDM
Posted on 2003-08-12 10:53:54 by donkey
ok so i would use this right,



.while ebx!=2
inc ebx
invoke GetDlgItem, hWin, IDC_MONLIST
invoke SendMessage, eax, LB_ADDSTRING, -1, offset text
invoke SendMessage, hWin, LB_SETITEMDATA, eax, IDC_MONLIST
invoke SendMessage, eax, LB_GETCURSEL, 0, 0
.break.if ebx==2
.endw
-----------
heres my string
text db "1.something",0
db "2.somthing else",0



is that right?
--edit
sorry just saw ur post donkey,

i add that macro into my code and then call it? but then do i need to input any specific data besides the LB_SetContent IDC_MONLIST,OFFSET text

thanks,
njkt
Posted on 2003-08-12 10:54:32 by njkt809
Nope, that loop will add the first item twice. You are passing always "offset text"! You need to pass the offset of each item. I think donkey's macros are great, you should use those, unless you want to experiment and try to program the loop yourself...


.data
text db "1.something",0
db "2.somthing else",0
db 0 ;Note the extra ending "0" here... if you don't place it here, it will never stop...

.code
LB_SetContent hListBox,OFFSET text
Posted on 2003-08-12 11:04:56 by QvasiModo
Another option, a quick and dirty one :)
There's no real improvement, donkey's macros are still better, but I'm posting this so you can get the idea of one of the many ways in wich you can implement this.


.data
text db "1.something",0
db "2.somthing else",0

.code
push ebx
push esi
push edi
mov ebx,NUMBER_OF_ITEMS
mov esi,offset text
invoke GetDlgItem,hWin,IDC_MONLIST ;Get the control handle
mov edi,eax
.repeat
invoke SendMessage,edi,LB_ADDSTRING,-1,esi ;Add the item
invoke lstrlen,esi ;Go to next item offset
add esi,eax
inc esi
dec ebx ;Decrement counter until it reaches zero
.until zero?
invoke SendMessage,edi,LB_SETCURSEL,0,0 ;Set the initial selection
pop edi
pop esi
pop ebx
Posted on 2003-08-12 11:10:07 by QvasiModo