Jump to content

Recommended Posts

Posted (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 by EKY32

[font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font]

Posted (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 by Andreik
Posted

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]

Posted (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 :

#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 by FireFox
Posted

Mr.FireFox :bye:

Thank you very much, thanks to every one who helped. :wub:

[font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font]

Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...