函数参考


_GUICtrlListBox_AddString

添加字符串

#include <GuiListBox.au3>
_GUICtrlListBox_AddString($hWnd, $sText)

参数

$hWnd 控件的控件ID/句柄
$sText 添加的字符串

返回值

成功: 返回 字符串的 0 基索引
失败: 返回 -1

注意/说明

如果内存空间不足,则返回值为 $LB_ERRSPACE.

如果列表框没有 $LBS_SORT 样式, 字符串被添加到列表框的末尾;
否则,该字符串被插入到列表框自动排序位置.

相关

_GUICtrlListBox_InsertString, _GUICtrlListBox_DeleteString, _GUICtrlListBox_AddFile, _GUICtrlListBox_InitStorage

示例/演示


#include <GuiListBox.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Debug_LB = False ;检查传递给 ListBox 函数的类名, 设置为True并输出到一个控件的句柄,用于检查它是否工作

_Main()

Func _Main()
    Local $hListBox

    ; 创建 GUI
    GUICreate("List Box Add String", 400, 296)
    $hListBox = GUICtrlCreateList("", 2, 2, 396, 296, BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_DISABLENOSCROLL, $WS_HSCROLL))

    GUISetState()

    ; 添加字符串
    _GUICtrlListBox_BeginUpdate($hListBox)
    For $iI = 1 To 9
        _GUICtrlListBox_AddString($hListBox, StringFormat("%03d : Random string", Random(1, 100, 1)))
    Next
    _GUICtrlListBox_InsertString($hListBox, "Exact teXt", 3)
    _GUICtrlListBox_InsertString($hListBox, "This is the string that we're looking for", 6)
    _GUICtrlListBox_InsertString($hListBox, _
            "Let's add one really long line of text so that we can set the horizontal scroll bar and " & _
            "show that, unless we dynamically update the scroll bar, it won't show the full line.", 9)
    _GUICtrlListBox_UpdateHScroll($hListBox)
    _GUICtrlListBox_EndUpdate($hListBox)

    ; 循环直到用户退出
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main