Hi njkt809,

I originally wrote that macro to handle the arrays that Windows returns when you call some functions that return multiple strings. The array has to be in the same format as Windows uses (a list of zero terminated strings terminated by an extra zero) Besides that there are no resritcions except that you cannot use edi,esi, ecx or eax to pass a parameter as they are altered internally.
Posted on 2003-08-12 11:11:15 by donkey
ok that works very well,
im sorry i dont knwo how to use the macros very well right now.

thanks njkt
Posted on 2003-08-12 11:11:56 by njkt809
ok so then for the seletc items it would be
invoke SendMessage, LB_GETSELITEMS, 3, textbuffer
would that be right?
then what do i do after the item is seleted? how do i jump to a proc based on the selection?

thanks,
njkt

(gtg haha time for highschool registration :rolleyes: )
Posted on 2003-08-12 11:17:14 by njkt809
This will do... take a look at the macro's source and you will know how it works. Feel free to post any questions :)


.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...

hListBox dd 0 ;This is the variable where we store the control handle

.code
; This goes into ArenaProc, where you handle WM_INITDIALOG
invoke GetDlgItem,hWin,IDC_MONLIST ;Get the control handle
mov hListBox,eax
LB_SetContent hListBox,OFFSET text ;Add the items
invoke SendMessage,edi,LB_SETCURSEL,0,0 ;Set the initial selection, use a variable instead if you want
Posted on 2003-08-12 11:19:44 by QvasiModo

ok so then for the seletc items it would be
invoke SendMessage, LB_GETSELITEMS, 3, textbuffer
would that be right?
then what do i do after the item is seleted? how do i jump to a proc based on the selection?

If you want the user to select only one item, you can use the LB_GETCURSEL message, it's easier to handle. If you want the user to be able to select several items, then use this:


invoke SendMessage, LB_GETSELITEMS, 3, [color=red]offset[/color] textbuffer

Don't forget the "offset"! If you don't use it, MASM thinks you want to read the first 4 bytes of your string and push that, instead of the address where the full string resides.

Then simply use an .if to handle the branching. If you use LB_GETCURSEL the selection is in EAX.
Posted on 2003-08-12 11:22:18 by QvasiModo
hey,
well i dont quiet get how to tell if the item is seled and then do an action based on the selection,
sorry for bein a bother about it,
but how would i do it?
it would be


invoke SendMessage, hWin, LB_GETCURSEL,0,0

but how do i tell what item is being selected?

thanks,
njkt
Posted on 2003-08-12 14:00:11 by njkt809

hey,
well i dont quiet get how to tell if the item is seled and then do an action based on the selection,
sorry for bein a bother about it,
but how would i do it?
it would be


invoke SendMessage, hWin, LB_GETCURSEL,0,0

but how do i tell what item is being selected?

thanks,
njkt

Don't worry, you're not bothering anyone :)

It would be:


invoke SendMessage,hListbox,LB_GETCURSEL,0,0

Where "hListbox" is the handle to the control, not to the main window. This is important because sending the message to the wrong window will simply fail without a warning, or will behave strangely. If you didn't store the control handle in a variable, you can always retreive it like this:


invoke GetDlgItem,hWin,IDC_MONLIST

Naturally, "hWin" is the handle to the parent window, and "IDC_MONLIST" is the ID of the control, as defined in the resource script.
Posted on 2003-08-12 16:05:22 by QvasiModo
The way I usually tell is to check for an LBN_SELCHANGE:
[b]In your windowproc[/b]

.ELSEIF uMsg == WM_COMMAND
mov eax,wParam
shr eax,16
.IF ax == LBN_SELCHANGE
invoke SendMessage,lParam,LB_GETCURSEL,0,0
; There has been a new selection made and the item index is in eax
.ELSEIF ax == LBN_DBLCLK
invoke SendMessage,lParam,LB_GETCURSEL,0,0
; The user has double-clicked an entry and the item index is in eax
.ENDIF
Posted on 2003-08-12 16:19:33 by donkey
hey,
well ok this is what i wanna do,
i want to be able to select the itemon the list, and in the box next to it have info about the item selection,
then be able to click a button and have it preform the action.
how would i do this?

thanks,
njkt
Posted on 2003-08-12 18:15:48 by njkt809

hey,
well ok this is what i wanna do,
i want to be able to select the itemon the list, and in the box next to it have info about the item selection,
then be able to click a button and have it preform the action.
how would i do this?

thanks,
njkt

Well, I would use an array of pointers for that:
.data

desc0 db "This is description 0",0
desc1 db "This is description 1",0
desc2 db "This is description 2",0
desc3 db "This is description 3",0
desc4 db "This is description 4",0

descarray dd OFFSET desc0
dd OFFSET desc1
dd OFFSET desc2
dd OFFSET desc3
dd OFFSET desc4
.code

[b]In your windowproc[/b]
.ELSEIF uMsg == WM_COMMAND
mov eax,wParam
shr eax,16
.IF ax == LBN_SELCHANGE
invoke SendMessage,lParam,LB_GETCURSEL,0,0
; There has been a new selection made and the item index is in eax
.IF eax != LB_ERR
invoke SetDlgItemText,hWin,DescrBoxID,descarray[eax*4]
.ENDIF
.ENDIF
Posted on 2003-08-12 19:11:29 by donkey
ok so then my code should be


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

mov eax, iMsg
.if eax==WM_INITDIALOG

push ebx
push esi
push edi
mov ebx,18
mov esi,offset Monsters
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


.elseif eax==WM_COMMAND
mov eax,wParam
mov edx,eax
shr edx,16
.if dx==BN_CLICKED
.if eax==IDC_OK
invoke EndDialog,hWin,0

.elseif eax==IDCANCEL
invoke EndDialog,hWin,0
.elseIF ax == LBN_SELCHANGE
invoke SendMessage,lParam,LB_GETCURSEL,0,0
; There has been a new selection made and the item index is in eax
.IF eax != LB_ERR
invoke SetDlgItemText,hWin,IDC_MONSTAT,descarray[eax*4]
.ENDIF
.endif


.endif
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret

ArenaProc endp

correct?

njkt
Posted on 2003-08-12 22:39:02 by njkt809
You should always preserve the esi edi and ebx registers in your windowproc. It will prevent bizarre crashes...

ArenaProc proc [b]uses edi esi ebx[/b] hWin:HWND,iMsg:UINT,wParam:WPARAM,lParam:LPARAM


use can also get rid of these lines because that is what the uses directive will do :

push ebx
push esi
push edi

and

pop edi
pop esi
pop ebx
Posted on 2003-08-12 22:57:44 by donkey
ok everything works now,
so then heres my question,
how do i use buttons?
after i put in that code i cant use any buttons.
-edit-
ok i found it looking at one of ur examples (found a while ago)
here it is in its entirety (spelling? haha)


ArenaProc proc uses edi esi ebx hWin:HWND,iMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL IDFrom :DWORD

mov eax, iMsg
.if eax==WM_INITDIALOG
;this is the listbox
mov ebx,18
mov esi,offset Monsters
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

; There has been a new selection made and the item index is in eax


;----------------------------------------------------------
.ELSEIF iMsg == WM_COMMAND
mov eax,wParam
mov IDFrom,eax
shr eax,16
;this is the description (editbox)
.IF ax == LBN_SELCHANGE
invoke SendMessage,lParam,LB_GETCURSEL,0,0
; There has been a new selection made and the item index is in eax
.IF eax != LB_ERR
invoke SetDlgItemText,hWin,IDC_MONSTAT,descarray[eax*4]
.ENDIF
;this is the buttons
.elseIF IDFrom == 1018 && eax == BN_CLICKED
invoke EndDialog,hWin,0
.endif
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret

ArenaProc endp



thanks for the help,
but still,
how do i find which selection is chosen then do stuff based on it?

thanks,

njkt
Posted on 2003-08-13 14:52:24 by njkt809
thanks for the help,
but still,
how do i find which selection is chosen then do stuff based on it?

Maybe you should read a bit in the API reference yourself. LB_GETCURSEL is the message (it is commented), it has been explained several times in this thread. There is also a reference to it in my code that get the currently selected item in the Listbox. QvasiModo explained it earlier in the thread as well. Helping is one thing but explaining the same thing over and over for 40 posts is a little much :o
Posted on 2003-08-13 17:16:25 by donkey
lolz sorry i figured it out but my modem was being dumb so i couldnt edit my post untill now,

i got it all down except for arrays which im looking into.

thanks,
njkt
Posted on 2003-08-13 17:18:34 by njkt809