EKY32 Posted August 31, 2012 Share Posted August 31, 2012 (edited) I need to insert a point to type a floating-point number, but I also need to deny the user from typing characters.. any help? Thank you. #include <EditConstants.au3> GUICreate("Title", 265, 132) GUICtrlCreateInput("", 32, 32, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER)) GUICtrlCreateLabel("Type 1.25 if you can :'(", 32, 72, 114, 17) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case -3 Exit EndSwitch WEnd Edited August 31, 2012 by EKY32 [font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font] Link to comment Share on other sites More sharing options...
Andreik Posted August 31, 2012 Share Posted August 31, 2012 (edited) Initialy you create an input control without $ES_NUMBER style and then you can register WM_COMMAND message and then you can check when $EN_UPDATE message is received and then replace the input of control to keep just characters you want. Edited August 31, 2012 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
JohnOne Posted August 31, 2012 Share Posted August 31, 2012 I do not believe the is a constant style for this. You would most likely have to do a check on anything entered into Input control before actioning on its contents. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
EKY32 Posted August 31, 2012 Author Share Posted August 31, 2012 Initialy you create an input control without $ES_NUMBER style and then you can register WM_COMMAND message and then you can check when $EN_UPDATE message is received and then replace the input of control to keep just characters you want.Thank you, but I see this way is too long! I need a best smart way if any. [font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font] Link to comment Share on other sites More sharing options...
FireFox Posted August 31, 2012 Share Posted August 31, 2012 (edited) Initialy you create an input control without $ES_NUMBER style and then you can register WM_COMMAND message and then you can check when $EN_UPDATE message is received and then replace the input of control to keep just characters you want. Hi, Here is what Andreik was thinking about : expandcollapse popup#include <WindowsConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> Opt("GUIOnEventMode", 1) GUICreate("toto") GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $tbMyInputNumber = GUICtrlCreateEdit("", 10, 10, 100, 20, $ES_AUTOHSCROLL) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState() While 1 Sleep(1000) WEnd Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $iCode = BitShift($wParam, 16) Local $iIDFrom = _WinAPI_LoWord($wParam) Switch $iIDFrom Case $tbMyInputNumber Switch $iCode Case $EN_UPDATE Local $sWMCOMMAND_MyInputNumberRead = GUICtrlRead($tbMyInputNumber) Local $sWMCOMMAND_MyInputNumberLastChar = StringRight($sWMCOMMAND_MyInputNumberRead, 1) Local $aWMCOMMAND_MyInputNumberDotSplit = StringSplit($sWMCOMMAND_MyInputNumberRead, ".") If $aWMCOMMAND_MyInputNumberDotSplit[0] > 2 Or (Not StringIsInt($sWMCOMMAND_MyInputNumberLastChar) And $sWMCOMMAND_MyInputNumberLastChar <> ".") Then GUICtrlSetData($tbMyInputNumber, StringTrimRight($sWMCOMMAND_MyInputNumberRead, 1)) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Func _Exit() Exit EndFunc And I'm sure this can be more clear with a RegExp test. Br, FireFox. Edited August 31, 2012 by FireFox Aelc 1 Link to comment Share on other sites More sharing options...
EKY32 Posted August 31, 2012 Author Share Posted August 31, 2012 Mr.FireFox Thank you very much, thanks to every one who helped. [font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font] Link to comment Share on other sites More sharing options...
JohnOne Posted August 31, 2012 Share Posted August 31, 2012 This is something like what I had in mind. #include <EditConstants.au3> GUICreate("Title", 265, 132) $hInput = GUICtrlCreateInput("", 32, 32, 121, 21, $GUI_SS_DEFAULT_INPUT) GUICtrlCreateLabel("Type 1.25 if you can :'(", 32, 72, 114, 17) $button = GUICtrlCreateButton("go", 172, 72, 20, 20) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case -3 Exit Case $button $Number = _CheckInput($hInput) EndSwitch WEnd Func _CheckInput($var) Local $sInput = GUICtrlRead($var) MsgBox(0,0,Number($sInput)) Return Number($sInput) EndFunc AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now