Mmm... Amazing how tyring to show one example got me into such a sewer :) If it wasn't for the strange behavior of Windows when it comes to Numeric only I would agree, but there is the problem of the pasting of characters. I think that the WM_PASTE can stay but you have to get rid of the lpTranslated and set the style to numeric only. The CTRL-V paste may be taken care of by the WM_PASTE message.
Posted on 2003-06-03 00:54:03 by donkey
Aaaargh ! :mad: :mad:

Try this, it seems to do everything now. If the value is not readable it will just take the number as far as it can read and put that in, otherwise it should put a zero.
LimitWndProc PROC hEdit:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

LOCAL hParent :DWORD
LOCAL idCtrl :DWORD
LOCAL lpTranslated :DWORD
LOCAL OldValue :DWORD
LOCAL Limit :DWORD

.if uMsg==WM_CHAR || uMsg==WM_PASTE
invoke GetParent,hEdit
mov hParent,eax
invoke GetDlgCtrlID,hEdit
mov idCtrl,eax
invoke GetWindowLong,hEdit,GWL_USERDATA
mov Limit,eax
invoke GetDlgItemInt,hParent,idCtrl,ADDR lpTranslated,FALSE
mov OldValue,eax
invoke CallWindowProc,OldWndProc,hEdit,uMsg,wParam,lParam
push eax
invoke GetDlgItemInt,hParent,idCtrl,ADDR lpTranslated,FALSE
.IF eax > Limit
invoke SetDlgItemInt,hParent,idCtrl,OldValue,FALSE
.ELSEIF lpTranslated == FALSE
invoke SetDlgItemInt,hParent,idCtrl,eax,FALSE
.endif
pop eax
.else
invoke CallWindowProc,OldWndProc,hEdit,uMsg,wParam,lParam
.endif
ret
LimitWndProc endp
Posted on 2003-06-03 01:08:46 by donkey
How about this slight change?:
LimitWndProc PROC hEdit:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

LOCAL hParent :DWORD
LOCAL idCtrl :DWORD
LOCAL OldValue :DWORD
LOCAL Limit :DWORD

.if uMsg==WM_CHAR || uMsg==WM_PASTE
invoke GetParent,hEdit
mov hParent,eax
invoke GetDlgCtrlID,hEdit
mov idCtrl,eax
invoke GetWindowLong,hEdit,GWL_USERDATA
mov Limit,eax
invoke GetDlgItemInt,hParent,idCtrl,NULL,FALSE
mov OldValue,eax
invoke CallWindowProc,OldWndProc,hEdit,uMsg,wParam,lParam

push eax
invoke GetDlgItemInt,hParent,idCtrl,NULL,FALSE
.IF eax > Limit
mov eax,OldValue
.endif
invoke SetDlgItemInt,hParent,idCtrl,eax,FALSE
pop eax
.else
invoke CallWindowProc,OldWndProc,hEdit,uMsg,wParam,lParam
.endif
ret
LimitWndProc endp
The bonus is that any extra pasted characters or leading zeroes are gone. :)
Posted on 2003-06-03 01:17:57 by bitRAKE
Bazik, with your version the digits gets typed in reversed, since the caret gets reset to the beggining for every digit typed. ..:tongue:
I'm trying to figure something out...hard though.
Would it solve it if saving caret-position before updating edit-box, and then restoring it? Is it possible?

For Donkey's latest version, only thing I can think of is adding in the beginning


.if wParam==8 ; backspace char
invoke CallWindowProc,OldWndProc,hEdit,uMsg,wParam,lParam
ret
.endif

So one can delete the 0.
Posted on 2003-06-03 04:19:03 by david
OK, the final final final version. This one will select the whole number if it goes over or under. It will also change the number to the maximum value if a higher value is entered and to zero if an illegal character is entered. I think that this is the best of all worlds. The bug in the Windows Numeric Only style limits the possibilites without creating a custom control:
LimitWndProc PROC hEdit:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

LOCAL hParent :DWORD
LOCAL idCtrl :DWORD
LOCAL lpTranslated :DWORD
LOCAL OldValue :DWORD
LOCAL Limit :DWORD
LOCAL SelStart :DWORD

.if uMsg==WM_CHAR || uMsg==WM_PASTE
invoke GetParent,hEdit
mov hParent,eax
invoke GetDlgCtrlID,hEdit
mov idCtrl,eax
invoke GetWindowLong,hEdit,GWL_USERDATA
mov Limit,eax
invoke GetDlgItemInt,hParent,idCtrl,ADDR lpTranslated,FALSE
mov OldValue,eax
invoke CallWindowProc,OldWndProc,hEdit,uMsg,wParam,lParam
push eax
invoke GetDlgItemInt,hParent,idCtrl,ADDR lpTranslated,FALSE
.IF eax > Limit
invoke SetDlgItemInt,hParent,idCtrl,Limit,FALSE
invoke SendMessage,hEdit,EM_SETSEL,0,-1
.ELSEIF lpTranslated == FALSE
invoke SetDlgItemInt,hParent,idCtrl,0,FALSE
invoke SendMessage,hEdit,EM_SETSEL,0,-1
.endif

pop eax
.else
invoke CallWindowProc,OldWndProc,hEdit,uMsg,wParam,lParam
.endif
ret
LimitWndProc endp
Any more bugs in this one and I give up :)
Personally, I see no reason to delete the zero, it is implied anyway that no text is zero so if it's there it makes no difference.
Posted on 2003-06-03 07:23:13 by donkey
:mad: Can't find any more bugs!! ( *joking* :grin: )

:alright::alright: Smart with the selecting of the text, that solves everything!!
Posted on 2003-06-04 02:57:31 by david
k I take the I want to convert it from dec to hex, how do I fix the limitations on the box to allow hex chars and limit it at FF?
Posted on 2003-06-04 15:48:10 by EEDOK
Hi EEDOK,

That's a bit more complicated but you should be able to figure it out with what we've shown here. Just use a hex filter for the character level entry instead of the numeric only style. I think you'll have to loose some of the intrinsic editing functions or make allowance for them in your filter. Iczelion's tutorial covers hex only edit controls, it wouldn't be much to adapt them.

PS: My routine is not adaptable to HEX !
Posted on 2003-06-04 16:17:20 by donkey
Posted on 2003-06-08 19:41:45 by EEDOK
My htob


htob:
;input stored in ax, al = first byte, ah=second byte
or eax,02020h
sub eax,03030h
test eax,030h
jz @F
sub eax,027h
@@:
test eax,03000h
jz @F
sub eax,02700h
@@:
shl al,4
or al,ah
and eax,0ffh
retn

Just abit of slipshort work.

Anyway to make it limit the input to be hex code just subclass and limit the entry to be only of '0'-'9' and 'A'-'F'and 'a'-'f'
I change abit of the code to use only eax.
Posted on 2003-06-12 03:01:04 by roticv
Why can you send it this message?

ES_NUMBER
Allows only digits to be entered into the edit control.

Edit Control allow you to make this setting or am I missing something?

RobotBob
Posted on 2003-06-12 03:07:25 by RobotBob
Hi RobotBob,

There is an apparent bug in the API (all versions of Windows) that allows you to paste alpha into a numeric only edit box, also he was looking for a way to limit the high number that could be entered. We were working out a way to limit the entry real-time. Try a ctrl-V paste in an edit control with ES_NUMBER set or a right-click paste, it accepts everything not just numbers.
Posted on 2003-06-12 03:29:05 by donkey
I guess I've never pasted into a number only box lol.
I did miss something. I missed the post on WM_PASTE inteceptions.

And you said realtime, on every keypress not just the enter key.

How bout 'auto complete' edit boxes based on a keyword list?
I think your guys code is halfway there?
That would be great code to have.
(I am painfully hinting here, I have to write this soon myself,
auto-completing combo boxes)

And sorry again for not throughly reading the preceding posts.


RobotBob
Posted on 2003-06-12 03:43:25 by RobotBob
Something by comrade, though I think could be modified to your needs.
Posted on 2003-06-12 04:07:11 by roticv
THANK YOU! roticv .

This is exactly what I need!

Round of beers on me :)

RobotBob
Posted on 2003-06-12 04:57:25 by RobotBob
Roticv, what does your htob proc do? I don't get it?! :stupid:
Posted on 2003-06-12 07:04:16 by david
For example:



.data
somestring db "A1",0
.data?
buffer db 3 dup (?)

.code
xor eax,eax
lea esi, somestring
lodsw
call htob
invoke dwtoa,eax, offset buffer
invoke MessageBox, 0,offset buffer,0,0

The messagebox will show 161 (A1h).
Posted on 2003-06-12 07:42:00 by roticv