Dear ALL:

i have some question about the combobox regarding how to put an item
in combobox in a loop so that i will not type SendMessage manytimes

like for example:

invoke CreateWindowEx,NULL,addr ComboClass,addr szText01,WS_VISIBLE or WS_CHILD or WS_VSCROLL or CBS_DROPDOWNLIST,37,22,150,150,hWnd,ComboboxID,hInstance,NULL

mov hCombobox01,eax

invoke SendMessage,hCombobox01,CB_SETITEMDATA,0,ADDR szText02
invoke SendMessage,hCombobox01,CB_ADDSTRING,0,ADDR szText03
invoke SendMessage,hCombobox01,CB_ADDSTRING,0,ADDR szText04
invoke SendMessage,hCombobox01,CB_ADDSTRING,0,ADDR szText05
invoke SendMessage,hCombobox01,CB_ADDSTRING,0,ADDR szText06
invoke SendMessage,hCombobox01,CB_ADDSTRING,0,ADDR szText07

i want one line of code to do it posible?
if yes kindly explain it to me in basic form... thank you..

Yours truly,
Posted on 2003-11-05 19:57:25 by coredump
I posted a macro to do this on the book page. You can create an array of items like this:

cbitems db "item1",0,"item2",0,"item3",0,0 <- note the extra zero at the end

use this macro to add the items:

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

In your program just include this line

CB_SetContent hCombobox,OFFSET cbitems
Posted on 2003-11-05 21:15:34 by donkey
wow! great i got it. thank you!..can i ask you one question?
how can i change the font of combobox?i want to set the font
of combobox to Tahoma size this posible?
Thank you in advance..

Posted on 2003-11-05 21:38:47 by coredump
Easy enough, you create the font and use WM_SETFONT to assign it to the combobox:


Tahoma8 LOGFONT <-10,0,0,0,FW_NORMAL,FALSE,FALSE,0,0,0,0,0,0,"Tahoma">
hTahoma8 dd 0
invoke CreateFontIndirect, OFFSET Tahoma8
mov hTahoma8, eax

invoke SendMessage, hCombobox, WM_SETFONT, hTahoma8, TRUE

; Be sure to delete the font when your program is done
invoke DeleteObject, hTahoma8
Posted on 2003-11-05 21:45:24 by donkey
You can use my variant with SendMessage API

szText1 db "This is combo Item 1",0
szText2 db "This is combo Item 2",0
szText3 db "This is combo Item 3",0
szText4 db "This is combo Item 4",0
szText5 db "This is combo Item 5",0
szText6 db "This is combo Item 6",0
szText7 db "This is combo Item 7",0

AddStr dd szText1,szText2, szText3, szText4
dd szText5,szText6, szText7


invoke CreateWindowEx,NULL,addr ComboClass,addr szText1,WS_VISIBLE or WS_CHILD ;or WS_VSCROLL or CBS_DROPDOWNLIST,37,22,150,150,hWnd,ComboboxID,hInstance,NULL
mov hCombobox01,eax

;push esi ; preserve registers
;push edi
;push ebx
;push ebp

mov edi, dword ptr [SendMessage+2] ; edi->jmp address of SendMessage API
mov esi, offset AddStr
mov ebp, eax ; ebp=eax-> hCombobox01
mov edi, [edi] ; edi->real address of SendMessage API
mov ebx, 7 ; ebx-> num of Items = 7
mov eax, [esi] ; esi-> current address in the table
add esi, 4 ; esi-> next address
push eax ; eax->current string address
push 0 ; zero
push CB_ADDSTRING ; message
push ebp ; ebp-> hCombobox01
call edi ; edi-> SendMessage API
add ebx, -1 ; dec counter-> num of Items = 7
jne Loop1

;pop ebp ; restore registers
;pop ebx
;pop edi
;pop esi

Posted on 2003-11-05 23:52:14 by lingo12
you mean i have to right this code in WM_CLOSE?
without DeleteObject the program is still running.
What is the difference?can you explain it to me
BTW Thank you so much..

.elseif uMsg == WM_CLOSE
invoke DeleteObject,hFont

Yours Truly,
Posted on 2003-11-06 00:03:03 by coredump
Thank you about the code but i encounter a problem if i use to build it this
is no problem but if i try to run the program the program will not appear.

Your Truly,
Posted on 2003-11-06 00:16:32 by coredump
Ok, this is fast too (see my edited message)
Posted on 2003-11-07 21:31:15 by lingo12