Hello,

I want to add numbers from 2 to 99 to a combobox. How can i do this?
How can it be done faster?
Posted on 2006-09-19 11:41:05 by hakand
The following works for me:


.data
FormatString db "%d",0


LOCAL Buffer[2]: BYTE
.
.
.
xor ecx, ecx
inc ecx
AddNext:
inc ecx
push ecx

invoke wsprintf, ADDR Buffer, ADDR FormatString, ecx

invoke SendMessage, hWndCombo, CB_ADDSTRING, NULL, ADDR Buffer

pop ecx
cmp ecx, 99
jne AddNext


or without the invoke syntax


.data
FormatString db "%d",0


LOCAL Buffer[2]: BYTE
.
.
.
xor ecx, ecx
inc ecx
AddNext:
inc ecx
push ecx

push ecx
push OFFSET FormatString
lea eax, DWORD PTR
push eax
call wsprintf

lea eax, DWORD PTR
push eax
push 0
push CB_ADDSTRING
push hWndCombo
call SendMessage

pop ecx
cmp ecx, 99


Note: It's a bit hard to say how it can be done faster if you haven't shown any code to start with ;)
Posted on 2006-09-19 23:32:05 by Timbo
Thank you Timbo.

By the word "faster" I meant, without using an API such as wsprint. Just using our own small and optimized proc if there are any.
Posted on 2006-09-21 07:53:51 by hakand
Ah, I see.  In the short time i've been using this board, I've come across a number of integer -> string conversion routines.  Just search the board for dword to string or int to string and you'll come up with something.  Here's some threads that might help you.

http://www.asmcommunity.net/board/index.php?topic=8716
http://www.asmcommunity.net/board/index.php?topic=16030
Posted on 2006-09-21 18:45:18 by Timbo
hakand: in this particular example I wouldn't worry too much about speed, even on the slowest machine able to run win95 it would be irrelevant :). But of course there's other situations where integer->string speed can matter, so it's a useful technique to know.

Also, moving this thread to WinAPI, since Algorithms is more about presenting and testing algorithms.
Posted on 2006-09-22 02:20:40 by f0dder