创建 ListBox (列表框)控件
#Include <GuiListBox.au3>
_GUICtrlListBox_Create($hWnd, $sText, $iX, $iY[, $iWidth = 100[, $iHeight = 200[, $iStyle = 0x00B00002[, $iExStyle = 0x00000200]]]])
$hWnd | 父窗口或属主窗口句柄 |
$sText | 添加到控件的字符串 |
$iX | 控件的水平位置 |
$iY | 控件的垂直位置 |
$iWidth | [可选参数] 控件宽度 |
$iHeight | [可选参数] 控件高度 |
$iStyle | [可选参数] 控件样式: $LBS_COMBOBOX - 通知列表框是组合控件的组成部分 $LBS_DISABLENOSCROLL - 显示停用的垂直滚动条 $LBS_EXTENDEDSEL - 允许一次选择多项 $LBS_HASSTRINGS - 列表框包含由字符串组成的项目 $LBS_MULTICOLUMN - 多列列表框,并可水平滚动 $LBS_MULTIPLESEL - 点击字符串时变换字符串选择状态 $LBS_NODATA - 列表框没有指定数据 $LBS_NOINTEGRALHEIGHT - 列表框大小由应用程序设置 $LBS_NOREDRAW - 当发生变化时,列表框的外观不更新 $LBS_NOSEL - 列表框包含可以查看但未被选中的项目 $LBS_NOTIFY - 单击或双击字符串时发送通知 $LBS_OWNERDRAWFIXED - 列表框由所有者绘制 $LBS_OWNERDRAWVARIABLE - 列表框所有者绘制可变高度 $LBS_SORT - 列表框按字母顺序排序字符串 $LBS_STANDARD - 标准列表框样式 $LBS_USETABSTOPS - 允许列表框识别和扩展制表符 $LBS_WANTKEYBOARDINPUT - 所有者接收 WM_VKEYTOITEM 消息 [可选参数] 默认 : $LBS_SORT, $WS_HSCROLL, $WS_VSCROLL, $WS_BORDER 强制 : $WS_CHILD, $WS_TABSTOP, $WS_VISIBLE, $LBS_NOTIFY |
$iExStyle | [可选参数] 控件扩展样式. 对应于标准 $WS_EX_ 常量. 默认 : $WS_EX_CLIENTEDGE |
成功: | 返回 ListBox 控件的句柄 |
失败: | 返回 0 |
#include <GuiListBox.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
$Debug_LB = False ;检查传递给 ListBox 函数的类名, 设置为True并输出到一个控件的句柄,用于检查它是否工作
Global $hListBox
_Main()
Func _Main()
Local $hGUI
; 创建 GUI
$hGUI = GUICreate("(UDF Created) List Box Create", 400, 296)
$hListBox = _GUICtrlListBox_Create($hGUI, "String upon creation", 2, 2, 396, 296)
GUISetState()
MsgBox(4160, "信息", "Adding Items")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
; 添加文件
_GUICtrlListBox_BeginUpdate($hListBox)
_GUICtrlListBox_ResetContent($hListBox)
_GUICtrlListBox_InitStorage($hListBox, 100, 4096)
_GUICtrlListBox_Dir($hListBox, @WindowsDir & "\win*.exe")
_GUICtrlListBox_AddFile($hListBox, @WindowsDir & "\notepad.exe")
_GUICtrlListBox_Dir($hListBox, "", $DDL_DRIVES)
_GUICtrlListBox_Dir($hListBox, "", $DDL_DRIVES, False)
_GUICtrlListBox_EndUpdate($hListBox)
; 循环直到用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>_Main
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg
Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox
If Not IsHWnd($hListBox) Then $hWndListBox = GUICtrlGetHandle($hListBox)
$hWndFrom = $ilParam
$iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
$iCode = BitShift($iwParam, 16) ; Hi Word
Switch $hWndFrom
Case $hListBox, $hWndListBox
Switch $iCode
Case $LBN_DBLCLK ; Sent when the user double-clicks a string in a list box
_DebugPrint("$LBN_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; 没有返回值
Case $LBN_ERRSPACE ; Sent when a list box cannot allocate enough memory to meet a specific request
_DebugPrint("$LBN_ERRSPACE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; 没有返回值
Case $LBN_KILLFOCUS ; Sent when a list box loses the keyboard focus
_DebugPrint("$LBN_KILLFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; 没有返回值
Case $LBN_SELCANCEL ; Sent when the user cancels the selection in a list box
_DebugPrint("$LBN_SELCANCEL" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; 没有返回值
Case $LBN_SELCHANGE ; Sent when the selection in a list box has changed
_DebugPrint("$LBN_SELCHANGE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; 没有返回值
Case $LBN_SETFOCUS ; Sent when a list box receives the keyboard focus
_DebugPrint("$LBN_SETFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; 没有返回值
EndSwitch
EndSwitch
; Proceed the default AutoIt3 internal message commands.
; You also can complete let the line out.
; !!! But only 'Return' (without any value) will not proceed
; the default AutoIt3-message in the future !!!
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
Func _DebugPrint($s_text)
$s_text = StringReplace($s_text, @LF, @LF & "-->")
ConsoleWrite("!===========================================================" & @LF & _
"+===========================================================" & @LF & _
"-->" & $s_text & @LF & _
"+===========================================================" & @LF)
EndFunc ;==>_DebugPrint