Search code examples
winapiassemblyx86tasm

How to convert an editbox to a number assembly?


In TASM for Win32, I have this code:

;------- Edit1 Create ----------------
push    L 0
push    [hInstEdit1]
push    idEdit1
push    [newhwnd]
push    L 20
push    L 200
push    L 50
push    L 130
push    L WS_CHILD+WS_VISIBLE+WS_BORDER+ES_LEFT+ES_NOHIDESEL+ES_AUTOHSCROLL
push    L 0
push    offset EClassName
push    L 0
call    CreateWindowEx
mov [hEdit1],EAX

push    L SW_SHOW
push    [hEdit1]
call    ShowWindow
push    [hEdit1]
call    UpdateWindow

I need to get the number entered by the user in this editbox. The number must be placed in the register. Who knows how to do this?

PS I think you need to use the function GetDlgItemInt


Solution

  • Here is the way found on the Internet

                                ; Input:
        mov esi, offset szMsg1  ; esi - str
        dec msgLength           
        mov ecx, msgLength      ; ecx - length str
                                ; Output:
                                ; EAX = integer value
    string_to_int:
        xor ebx,ebx             ; clear ebx
    next_digit:
        movzx eax, byte ptr [esi]
        inc esi
        sub al,'0'              ; convert from ASCII to number
        imul ebx,10
        add ebx,eax             ; ebx = ebx*10 + eax
        loop next_digit         ; while (--ecx)
        mov eax,ebx