By
crazyjts
Hi all,
I have the following snippet of code that sort of works but isn’t doing exactly what I want.
expand popup
#include <GuiConstants.au3>
Global $gGUIWidth = 250
Global $gGUIHeight = 150
Initial()
Func Initial()
; Create the initial GUI
$BaseGUI = GUICreate("", $gGUIWidth, $gGUIHeight, -1, -1, -1, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW)
GUISetState(@SW_SHOW, $BaseGUI)
; Create a field for entering the current value
GUICtrlCreateLabel("Current Value:", 10, 10)
$CurrentValueFld = GUICtrlCreateInput("", 10, 40, 215, 20, $ES_NUMBER)
GUICtrlSetState($CurrentValueFld, $GUI_FOCUS)
; Create Calculate button
Local $CalculateButton = GUICtrlCreateButton("Calculate", 10, 70, 75, 25)
GUICtrlSetState($CalculateButton, $GUI_DISABLE)
; Watch the value field and determine if the value is greater than 0 and if so, enable Calculate button
$i = 0
Do
$CurrentValue = GUICtrlRead($CurrentValueFld)
If $CurrentValue > 0 Then
GUICtrlSetState($CalculateButton, $GUI_ENABLE + $GUI_FOCUS)
$i = 1
EndIf
until $i = 1
;Loop until the user exits and check for ESC, "X", or Begin button
While 1
$InitialGUIMsg = GUIGetMsg()
If $InitialGUIMsg = $GUI_EVENT_CLOSE Then
Exit
EndIf
WEnd
EndFunc
I want to be able to:
Start with focus in the value field (it is doing this now)
Allow for more than one digit to be entered into the field (it is sort of doing this now but I have to bring focus back to the field)
Enable the Calculate button and give focus to it once a value is entered into the value field (it is doing this now) but keep the cursor in the value field so the more digits can be entered (it is not doing this now)
Be able to hit ESC or “X” to close the dialog at any time (this only works after I enter a digit in the value field
Basically, I want to be able to allow the user to enter one or more digits and hit ENTER or SPACE (while the cursor is still in the value field) to push the Calculate button. I assume I need to bring focus to the button but maybe I don't and can get away with assigning hotkeys for ENTER and SPACE to push the Calculate button while keeping focus in the value field.
If you could, please add comments in your code as to what the changes are doing if they aren't obvious to a noobish programmer.
Thanks for any help you can offer on this.