Function Reference


_GUICtrlEdit_Create

Create an Edit control

#include <GuiEdit.au3>
_GUICtrlEdit_Create ( $hWnd, $sText, $iX, $iY [, $iWidth = 150 [, $iHeight = 150 [, $iStyle = 0x003010C4 [, $iExStyle = 0x00000200]]]] )

Parameters

$hWnd Handle to parent or owner window
$sText Text to be displayed in the control
$iX Horizontal position of the control
$iY Vertical position of the control
$iWidth [optional] Control width
$iHeight [optional] Control height
$iStyle [optional] Control styles:
    $ES_AUTOHSCROLL - Automatically scrolls text to the right by 10 characters when the user types a character at the end of the line.
    $ES_AUTOVSCROLL - Automatically scrolls text up one page when the user presses the ENTER key on the last line.
    $ES_CENTER - Centers text in an edit control.
    $ES_LEFT - Aligns text with the left margin.
    $ES_LOWERCASE - Converts all characters to lowercase as they are typed into the edit control.
    $ES_MULTILINE - Designates a multiline edit control.
    $ES_NOHIDESEL - The selected text is inverted, even if the control does not have the focus.
    $ES_NUMBER - Allows only digits to be entered into the edit control.
    $ES_OEMCONVERT - Converts text entered in the edit control.
    $ES_READONLY - Prevents the user from typing or editing text in the edit control.
    $ES_RIGHT - Right-aligns text edit control.
    $ES_UPPERCASE - Converts all characters to uppercase as they are typed into the edit control.
    $ES_WANTRETURN - Specifies that a carriage return be inserted when the user presses the ENTER key.
    $ES_PASSWORD - Displays an asterisk (*) for each character that is typed into the edit control

Default: $ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL
Forced : WS_CHILD, $WS_VISIBLE, $WS_TABSTOP only if not using $ES_READONLY
$iExStyle [optional] Control extended style. These correspond to the standard $WS_EX_* constants. See Extended Style Table.

Return Value

Success: the handle to the Edit control.
Failure: 0.

Remarks

This function is for Advanced users and for learning how the control works.

Related

_GUICtrlEdit_Destroy

Example

Example 1

#include <GUIConstantsEx.au3>
#include <WinAPI.au3> ; used for Lo/Hi word
#include <GuiEdit.au3>
#include <WindowsConstants.au3>

Global $g_hEdit

Example()

Func Example()
    Local $hGUI

    ; Create GUI
    $hGUI = GUICreate("Edit Create", 400, 300)
    $g_hEdit = _GUICtrlEdit_Create($hGUI, "This is a test" & @CRLF & "Another Line", 2, 2, 394, 268)
    GUISetState(@SW_SHOW)

    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

    _GUICtrlEdit_AppendText($g_hEdit, @CRLF & "Append to the end?")

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

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit
    If Not IsHWnd($g_hEdit) Then $hWndEdit = GUICtrlGetHandle($g_hEdit)
    $hWndFrom = $lParam
    $iIDFrom = _WinAPI_LoWord($wParam)
    $iCode = _WinAPI_HiWord($wParam)
    Switch $hWndFrom
        Case $g_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" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->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" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->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" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $EN_ERRSPACE ; Sent when an edit control cannot allocate enough memory to meet a specific request
                    _DebugPrint("$EN_ERRSPACE" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $EN_HSCROLL ; Sent when the user clicks an edit control's horizontal scroll bar
                    _DebugPrint("$EN_HSCROLL" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $EN_KILLFOCUS ; Sent when an edit control loses the keyboard focus
                    _DebugPrint("$EN_KILLFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->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" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->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" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $EN_UPDATE ; Sent when an edit control is about to redraw itself
                    _DebugPrint("$EN_UPDATE" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->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" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

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

Example 2

#include <GUIConstantsEx.au3>
#include <WinAPI.au3> ; used for Lo/Hi word
#include <GuiEdit.au3>
#include <WindowsConstants.au3>

Global $g_hEdit

Example()

Func Example()
    Local $hGUI

    ; Create GUI
    $hGUI = GUICreate("Edit Create", 400, 300)
    $g_hEdit = _GUICtrlEdit_Create($hGUI, "", 2, 2, 394, 268)
    GUISetState(@SW_SHOW)

    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

    _GUICtrlEdit_SetText($g_hEdit, "This is a test" & @CRLF & "Another Line")

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

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit
    If Not IsHWnd($g_hEdit) Then $hWndEdit = GUICtrlGetHandle($g_hEdit)
    $hWndFrom = $lParam
    $iIDFrom = _WinAPI_LoWord($wParam)
    $iCode = _WinAPI_HiWord($wParam)
    Switch $hWndFrom
        Case $g_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" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->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" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->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" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $EN_ERRSPACE ; Sent when an edit control cannot allocate enough memory to meet a specific request
                    _DebugPrint("$EN_ERRSPACE" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $EN_HSCROLL ; Sent when the user clicks an edit control's horizontal scroll bar
                    _DebugPrint("$EN_HSCROLL" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $EN_KILLFOCUS ; Sent when an edit control loses the keyboard focus
                    _DebugPrint("$EN_KILLFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->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" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->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" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $EN_UPDATE ; Sent when an edit control is about to redraw itself
                    _DebugPrint("$EN_UPDATE" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->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" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

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