Jump to content

Recommended Posts

Posted

Is there a way to automatically call a function via GuiRegisterMsg or some Gui Event handling to detect when an Input Control or an Edit Control change it value? ie when a key is pressed when have focus.

I know you can use HotKeySet() to detect some keys and also you can use the while loop to check if an input control value has changed, but I want to know if there is another approach.

Another question, How can I select all the text in an input Control when it get the focused?

thanks in advance

Posted

Something to look at being an input control is a 1 line edit control

#include <GuiConstants.au3>
#include <GuiEdit.au3>
#include <GuiStatusBar.au3>
#include <WinAPI.au3> ; used for Lo/Hi word

Opt('MustDeclareVars', 1)

$Debug_Ed = False ; Check ClassName being passed to Edit functions, set to True and use a handle to another control to see it work

Global $hEdit

_Example_Internal()

Func _Example_Internal()
    Local $hGUI, $StatusBar, $sFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\include\changelog.txt" 
    Local $aPartRightSide[4] = [120, 248, 378, -1], $button

    ; Create GUI
    $hGUI = GUICreate("(Internal) Edit Get Modify", 400, 300)
    $hEdit = GUICtrlCreateInput("", 2, 2, 394, 25)
    $button = GUICtrlCreateButton("Ok", 10, 40, 90, 25)
    GUICtrlSetState($button, $GUI_DEFBUTTON)
    $StatusBar = _GUICtrlStatusBar_Create ($hGUI, $aPartRightSide)
    _GUICtrlStatusBar_SetIcon ($StatusBar, 3, 97, "shell32.dll")
    GUISetState()

    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

    ; Add Text
    _GUICtrlEdit_AppendText ($hEdit, "This is a test")

    ; Get Modified Flag
    _GUICtrlStatusBar_SetText ($StatusBar, "Modified: " & _GUICtrlEdit_GetModify ($hEdit), 2)
    
    GUICtrlSetState($button, $GUI_FOCUS)

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Example_Internal

Func _Input_Changed($hControl)
    _DebugPrint("Input Changed: " & _GUICtrlEdit_GetText ($hControl))
EndFunc   ;==>_Input_Changed

Func _Input_Focus($hControl)
    _DebugPrint("Input Got Focus")
    _GUICtrlEdit_SetSel ($hControl, 0, -1)
EndFunc   ;==>_Input_Focus

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit
    If Not IsHWnd($hEdit) Then $hWndEdit = GUICtrlGetHandle($hEdit)
    $hWndFrom = $ilParam
    $iIDFrom = _WinAPI_LoWord ($iwParam)
    $iCode = _WinAPI_HiWord ($iwParam)
    Switch $hWndFrom
        Case $hEdit, $hWndEdit
            Switch $iCode
                Case $EN_ALIGN_LTR_EC  ; Sent when the user has changed the edit control direction to left-to-right
                    _DebugPrint("$EN_ALIGN_LTR_EC" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $EN_ALIGN_RTL_EC  ; Sent when the user has changed the edit control direction to right-to-left
                    _DebugPrint("$EN_ALIGN_RTL_EC" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $EN_CHANGE  ; Sent when the user has taken an action that may have altered text in an edit control
                    _DebugPrint("$EN_CHANGE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    _Input_Changed($iIDFrom)
                    ; no return value
                Case $EN_ERRSPACE  ; Sent when an edit control cannot allocate enough memory to meet a specific request
                    _DebugPrint("$EN_ERRSPACE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $EN_HSCROLL  ; Sent when the user clicks an edit control's horizontal scroll bar
                    _DebugPrint("$EN_HSCROLL" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $EN_KILLFOCUS  ; Sent when an edit control loses the keyboard focus
                    _DebugPrint("$EN_KILLFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $EN_MAXTEXT  ; Sent when the current text insertion has exceeded the specified number of characters for the edit control
                    _DebugPrint("$EN_MAXTEXT" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; This message is also sent when an edit control does not have the $ES_AUTOHSCROLL style and the number of characters to be
                    ; inserted would exceed the width of the edit control.
                    ; This message is also sent when an edit control does not have the $ES_AUTOVSCROLL style and the total number of lines resulting
                    ; from a text insertion would exceed the height of the edit control

                    ; no return value
                Case $EN_SETFOCUS  ; Sent when an edit control receives the keyboard focus
                    _DebugPrint("$EN_SETFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    _Input_Focus($iIDFrom)
                    ; no return value
                Case $EN_UPDATE  ; Sent when an edit control is about to redraw itself
                    _DebugPrint("$EN_UPDATE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $EN_VSCROLL  ; Sent when the user clicks an edit control's vertical scroll bar or when the user scrolls the mouse wheel over the edit control
                    _DebugPrint("$EN_VSCROLL" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Posted

Something to look at being an input control is a 1 line edit control

Wow!!! Thank you very much Gary

And about my second question

How can I select all the text in an input Control when it get the focused?

Thanks again

Posted

Re: Second Question

I do something similar with one of my GUIs. After the main button is pressed, a series of events happen, last of which, I set a flag variable.

In the main GUI loop outside of the select case, I check for the flag. If the window's active and the flag is set, I highlight the main input box and select all the text in it.

If WinActive($hwndGUI) Then
        HotKeySet("{ESC}", "MyExit2")
        If $i_runFlag Then
            $i_runFlag = 0
            ControlSend($hwndGUI, "", $nptIndex, "{end}{shiftdown}{home}{shiftup}")
        EndIf
    Else
        HotKeySet("{ESC}")
    EndIfoÝ÷ Ú[ej׫¢x-jëh×6     Case $btnGo
            $prevclip = ClipGet()
            GUISetState(@SW_HIDE, $hwndGUI)
            $varTemp = _PrimaryDataLoop()
            ClipPut($prevclip)
            _LoliCheck()
            GUISetState(@SW_SHOW, $hwndGUI)
            Switch $varTemp
                Case 2
                    WinActivate($hwndCRU)
                Case 3
                    WinActivate($c)
                    WinActivate($a)
                Case 10 To 25000
                    WinActivate($hwndGUI)
                Case Else
                    WinActivate($varWin)
            EndSwitch
            DBP($version, "Awaiting new input" & @LF, 0, 0)
            $i_runFlag = 1 ; :::this is the key here:::

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

  • 2 months later...

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...