lhw Posted June 20, 2013 Share Posted June 20, 2013 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 20, 2013 Moderators Share Posted June 20, 2013 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:expandcollapse popup#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_COMMANDIf 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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