In case anybody is interested.
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)

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-1][-39h] ;it is faster code
sub eax,30h
xor ecx,eax
lea eax,[eax+30h]
jns @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
Posted on 2002-02-14 04:02:00 by The Svin
What happens if the user pastes a previously copied wrong number on the control ?
Posted on 2002-02-14 04:46:22 by JCP
Good question.
It doesn't control WM_PASTE at all.
Posted on 2002-02-14 04:58:19 by The Svin
Which way you prefer:
Restrict pasting
Validate pasting and/or converting it to needed format?
Posted on 2002-02-14 05:25:33 by The Svin
Cut-n-Paste is a very powerful method that should be supported, IMO. It should be converted to needed format. Very useful PROC Svin - this will get used by many!
Posted on 2002-02-14 10:09:26 by bitRAKE
just an idea
instead doing check for existing '.' when the user press on '.'

do global var (1 byte - could be 1 bit )

first time when the user press on '.' set the var to 1
when the user delete '.' set the var to 0

am.. this is just an idea not sure for speed



why do you check twice for dot?
Posted on 2002-02-14 13:07:31 by eko
To eko:
What do you mean by "why do you check twice for dot? "? :)
Durining one procedure call it can be done just once.
When the proc knows that it's WM_CHAR it processes one of three cases:

When case is found it processes it and returns.
One of features of the proc is that it allows not more the predifiend limit of digits after dot.
You can see the feature in many popular M$ Win proc (for example M$ Office Exel and Access)
"If there is dot " is checked by nested proc @havedot
if @havedot found a dot ZF flag is set, else SF. And havedots also returns address of next to the dot
byte in case a dot was found (ZF), else (SF) return value in eax is useless(addr of byte next to zero end).
@havedot may be called if it is case @ifdigit or @ifdot.
And because it is impossible that one char could represent and digit and dot @havedots may be called
just once per the EditFloat2 proc call.
If it is @ifdot call @havedot is called to determine if Edit control aready has a dot. In case it has - @havedot
would set ZF and further code will result in "zero return" preventing second digit in to edit control, else
in calls original Edit proc letting the dot into the edit control
If it is @ifdigit case @havedot is called for determination if there is dot and if there is - HOW MANY DIGITS
(if any) are after the dot.
if there is SF - then there is no dots and the proc allows digit into edit calling original proc
@havedot returns offset of next to dot symbol and proc sets counter searching for zero. Then it
checks value in counter against value wich represents how "many digits allowed after a dot" + 1.
Counter = 1 means not digits, 2 - 1 digit, 3 - 2 digits ...
We check it against 3 and if CF then it means that there is no digits after dot or just one digit and
we allow passed by WM_CHAR digit into edit. Else - we do zero return preventing the digit from passing into
If you want allow 3 digits - check the counter against 4, 4 - 5 ect.

Have I explained you question?
Posted on 2002-02-14 15:21:34 by The Svin
am... i'm not sure

i still not get why

lea ecx,[eax-1][-39h] ;it is faster code
sub eax,30h
xor ecx,eax
lea eax,[eax+30h]
jns @ifbk
call @havedot ; je - dot.. you know the user press on dot and you call to havedot to determinent if there is a dot allready, right ?
;js - no dots
;je - dot; eax-1 offset of the dot

why are you checking again for dot if you know from the code above when the user press on dot ?

cmp al,"."
jne @r0
call @havedot
jne accept
@r0: xor eax,eax
jmp @r


Posted on 2002-02-15 05:15:03 by eko
No, the first code lets the proc to know that user press digits not dot.
Posted on 2002-02-15 06:19:25 by The Svin