创建一个编辑框控件
#include <GuiEdit.au3>
_GUICtrlEdit_Create($hWnd, $sText, $iX, $iY [, $iWidth = 150 [, $iHeight = 150 [, $iStyle = 0x003010C4 [, $iExStyle = 0x00000200]]]])
$hWnd | 父窗口或者所有者窗口句柄 |
$sText | 控件上显示的文本 |
$iX | 控件水平坐标 |
$iY | 控件垂直坐标 |
$iWidth | [可选参数] 控件宽度 |
$iHeight | [可选参数] 控件高度 |
$iStyle | [可选参数] 控件样式: $ES_AUTOHSCROLL - 当用户输入到行尾时,自动滚动右侧文本 10 个字符. $ES_AUTOVSCROLL - 当用户在最后一行按下 ENTER 键时,自动向上滚动一页. $ES_CENTER - 编辑框控件文本居中. $ES_LEFT - 文本左对齐. $ES_LOWERCASE - 输入到编辑框中的字符转为小写. $ES_MULTILINE - 多行,强制的 $ES_NOHIDESEL - 当控件失去焦点时.选择的文本是反向的. $ES_NUMBER - 只允许在编辑框中输入数字. $ES_OEMCONVERT - 编辑控件文本输入转换(OEM). $ES_READONLY - 禁止用户在控件中输入或编辑文本. $ES_RIGHT - 文本右对齐. $ES_UPPERCASE - 输入到编辑框中的字符转为大写. $ES_WANTRETURN - 当用户按下 Enter 键时, 文本行插入一个回车符. $ES_PASSWORD - 当输入字符时显示星号(*). |
默认: $ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL 强制 : WS_CHILD, $WS_VISIBLE, $WS_TABSTOP only if not using $ES_READONLY |
|
$iExStyle | [可选参数] 控件扩展样式. 对应于标准 $WS_EX_ 常量. |
成功: | 返回 编辑控件句柄 |
失败: | 返回 0 |
#include <GuiEdit.au3>
#include <WinAPI.au3> ; used for Lo/Hi word
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
$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
_Example1()
_Example2()
Func _Example1()
Local $hGUI
; 创建 GUI
$hGUI = GUICreate("Edit Create", 400, 300)
$hEdit = _GUICtrlEdit_Create($hGUI, "This is a test" & @CRLF & "Another Line", 2, 2, 394, 268)
GUISetState()
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
_GUICtrlEdit_AppendText($hEdit, @CRLF & "Append to the end?")
; 循环直到用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>_Example1
Func _Example2()
Local $hGUI
; 创建 GUI
$hGUI = GUICreate("Edit Create", 400, 300)
$hEdit = _GUICtrlEdit_Create($hGUI, "", 2, 2, 394, 268)
GUISetState()
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
_GUICtrlEdit_SetText($hEdit, "This is a test" & @CRLF & "Another Line")
; 循环直到用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>_Example2
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg
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)
; 没有返回值
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)
; 没有返回值
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)
; 没有返回值
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)
; 没有返回值
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)
; 没有返回值
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)
; 没有返回值
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
; 没有返回值
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)
; 没有返回值
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)
; 没有返回值
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)
; 没有返回值
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