Hi, how do I go about creating a number only input in a dialogbox? I assume I should use an EDITTEXT thing, but then what do I do? Can you subclass it?! Please can someone point me in the right direction? Thanks.
:stupid:
Posted on 2003-07-15 08:45:49 by adamjjackson
There's no need for subclassing... there is a window style for that: ES_NUMBER.
But if you want to get fancy, and use hex numbers, IP addresses and such, you'll have to either sub/super class or use a custom control. There's a custom controls subforum here.
Posted on 2003-07-15 09:20:31 by QvasiModo
Okay thanks, I hadn't been able to find that style. I just need plain old digits at present. I'd read somethings about sub/super classing. Seemed like it was just for controls though?
Anyway, that's irrelevant for the meantime! Thanks.
Posted on 2003-07-15 09:22:16 by adamjjackson
if i understood ur question right simply check "filtinpt" from the masm32 package
that?s an example that checks for numeric, Lcase and Ucase
Posted on 2003-07-15 09:31:18 by Allanon
From WINDOWS.INC:
ES_NUMBER equ 2000h

You can simply use this style when creating the control with CreateWindowEx, or in your dialog box definition in your resource script.
By the way, sub/super classing is for ANY window, not just controls... wich opens very interesting possibilities ;)
Posted on 2003-07-15 09:40:09 by QvasiModo
QvasiModo,
"There's no need for subclassing... there is a window style for that: ES_NUMBER."

"Edit Control Styles

ES_NUMBER -
Allows only digits to be entered into the edit control.
Note that, even with this set, it is still possible to paste non-digits into the edit control.
To change this style after the control has been created, use SetWindowLong. " from MSDN

Regards,
Lingo
Posted on 2003-07-15 15:45:10 by lingo12
The problem with ES_NUMBER is that the user can still copy and paste alpha into the edit control. There is a subclassing example Here that limits the entries to numbers within a 0-max range. Pass the maximum number in the GWL_USERDATA.
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
Posted on 2003-07-15 16:01:41 by donkey
Thanks for that, becuase I do need to limit the size of the number too. :)

This is now a little off topic, but can someone point me in the right direction with this too?! I have two of these number only fields, and would like to enable a button when they both contain numbers, before then it is disabled - for validation purposes. I know how to enable it, just not how to check that both fields contain the text. I can't just use the EN_CHANGE notification, as this I believe this is sent when the user clears the field too. :confused:
Thanks all!
Posted on 2003-07-16 06:24:35 by adamjjackson
Originally posted by lingo12
"Edit Control Styles

ES_NUMBER -
Allows only digits to be entered into the edit control.
Note that, even with this set, it is still possible to paste non-digits into the edit control.
To change this style after the control has been created, use SetWindowLong. " from MSDN

Didn't know that... I'll remember :)
Originally posted by adamjjackson
I can't just use the EN_CHANGE notification, as this I believe this is sent when the user clears the field too.

Can't you read the number with GetDlgItemInt? If bTranlated gives you an error, it means there is no number. As an alternative, you could read the text with GetWindowText and check if there is a number.
Posted on 2003-07-16 09:12:31 by QvasiModo
Yeah, GetDlgItemInt works fine. It's just I want the "OK" button to only be enabled when the control contains a number. I'm not sure how to do this. I assume I should have a boolean flag, but when to change the flag?
I'll play around for a while longer anyway :)
Posted on 2003-07-16 11:59:16 by adamjjackson
Well, I would use the EN_CHANGE notification message and wait for a response from both edits before I enabled the button. You can use two flags ANDed to verify the state of the button. If the EN_CHANGE message comes and the control has been cleared then you clear the flag otherwise it is true. When both conditions are true then the control is enabled. pseudo-code:

.if uMsg==EN_CHANGE
>> Select the flag based on the control ID
GetDlgItemInt
.IF error >> Clear the flag for this item (empty edit box)
.ELSE >> set the flag for this item
.IF flag[1] and flag[2] >> enable the button
Posted on 2003-07-16 12:23:11 by donkey
This was the topic of a recent thread....

Read this as well.

http://www.asmcommunity.net/board/index.php?topic=13597
Posted on 2003-07-16 12:44:36 by RobotBob
Same link I posted above (mine was formatted so you might not have seen it) the code I supplied was the solution I came up with for the other thread. It is a bit like we have one mind sometimes RobotBob :)
Posted on 2003-07-16 12:48:39 by donkey
heh I completely missed that link.lol
yes I have noticed we post nearly at the same time on some posts
sharing a mind is scary, since I know how disfunctional the half I own is :)

RobotBob
Posted on 2003-07-16 13:04:14 by RobotBob