Assembly code snippets

Back to the snippets overview


TitleSubclassed Edit for Float input
AuthorThe Svin
Submitted by:Thomas
Date added:2002-02-19 14:33:46
Date modified:2002-02-20 05:44:58


It is simple subclass proc for float numbers.
The main feature is that you can set limit of digits allowed after dot.
-Allows digits, 1 dot, and usage of backspace
- Allows only predefined number of digits after a dot.
Current code allows just 2 digits after dot.
You can change it to any number of your choise replacing just one simbol (see comments to see where)
I used here ECin method of determination if value is in given
range and also insert my method in comments (ECin's is faster
mine is shorter)
Note: it does not handle WM_PASTE.


EditFloat2 proc uses ebx edi esi hWnd,uMsg,wParam,lParam
LOCAL buffer[32]:BYTE
    cmp uMsg,WM_CHAR
    je @ifdigit
;pass the message to ERealProc - original edit proc
 invoke CallWindowProc,ERealProc,hWnd,uMsg,wParam,lParam
@r: ret
    mov eax,wParam
;   cmp al,3Ah ;it is shorter code
;   sbb cl,cl
;   cmp al,30h
;   adc cl,0
         lea ecx,[eax-30h]
         cmp ecx,9
    ja @ifbk
    call @havedot
;js - no dots
;je - dot; eax-1 offset of the dot
    js accept
    xor ecx,ecx
@@: cmp byte ptr [eax],30h
    lea eax,[eax+1]
    lea ecx,[ecx+1]
    jnc @B
    ;ecx - 1 = number of caracters after the dot
    cmp ecx,3 ;set here your limit of digits allowed after dot+ 1
    jnc @r0
    jmp accept
    cmp al,VK_BACK
    je accept
    cmp al,"."
    jne @r0
    call @havedot
    jne accept
@r0: xor eax,eax
    jmp @r

    xor eax,eax
    mov ecx,8
    lea edi,buffer
rep stosd
    invoke GetWindowText,hWnd,addr buffer,32
    lea eax,buffer
@@: cmp byte ptr [eax],"."
    lea eax,[eax+1]
    je @F   ;if dot
    jns @B  ;if zero
@@: retn

EditFloat2 endp