Sign in to follow this  
Followers 0
lhw

need help on initalizing input ctrl automatically

2 posts in this topic

hello, guys i got problem on getting input control to initial state, 
i need inputting number from 1- 256 to input control as conditions,then my app can do something, is there a way can automatically update input control to initial state without pressing backspace key when i input next number, i have worked around on this a couple hours with failure,  
Any help will be appreciated, lhw
 
my codes like below
 
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>

$GUI = GUICreate("Input Test", 278, 215)
$cInput = GUICtrlCreateInput("", 24, 16, 60, 30, $ES_NUMBER)
GUICtrlSetLimit(-1, 3, 1)

$Button = GUICtrlCreateButton("Button", 192, 152, 73, 33, $BS_DEFPUSHBUTTON)
$lab= GUICtrlCreateLabel("", 16, 80, 161, 105)
GUICtrlSetBkColor(-1, 0XFFFFFF)
GUICtrlSetData(-1, "")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        
        Case $Button        
              $DATA = GUICtrlRead($CInput)
              If $DATA >= 1 And $DATA <= 256 Then
            ;do something 
            GUICtrlSetData($LAB, $DATA)                 
             Else
            GUICtrlSetData($CInput, '')
            MsgBox(0, 0, 'invalid input')
             EndIf

    EndSwitch
WEnd
 

Share this post


Link to post
Share on other sites



lhw,

I would use a message handler to look for changes to the input and reset it to the last valid input - soemthing like this:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

; Declare a variable to hold the last valid input content
Global $iValid

$GUI = GUICreate("Input Test", 278, 215)
$cInput = GUICtrlCreateInput("", 24, 16, 60, 30, $ES_NUMBER)
GUICtrlSetLimit(-1, 3, 1)

$Button = GUICtrlCreateButton("Button", 192, 152, 73, 33, $BS_DEFPUSHBUTTON)
$lab = GUICtrlCreateLabel("", 16, 80, 161, 105)
GUICtrlSetBkColor(-1, 0XFFFFFF)
GUICtrlSetData(-1, "")
GUISetState(@SW_SHOW)

; Register our handler
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            GUICtrlSetData($lab, GUICtrlRead($cInput))
    EndSwitch
WEnd


Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $lParam

    $iCID = BitAND($wParam, 0xFFFF)
    $iCode = BitShift($wParam, 16)

    Switch $iCode
        Case $EN_CHANGE ; Something has changed in an input
            Switch $iCID
                Case $cInput ; And it is our input
                    $iContent = Number(GUICtrlRead($cInput))
                    Switch $iContent
                        Case 0 To 256 ; It is valid so save it
                            $iValid = $iContent
                        Case Else ; it is not valid so replace it with the last valid entry
                            GUICtrlSetData($cInput, $iValid)
                    EndSwitch
            EndSwitch
    EndSwitch

EndFunc   ;==>_WM_COMMAND
If you are not too familiar with Windows message handlers, I recommend the GUIRegisterMsg tutorial in the Wiki. ;)

All clear? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0