在 AHK 中附加一个 ListBox 列表

Appending a ListBox list in AHK

我有一个带有 "usernames" 的文本文件:

; info.txt
user1
user2
user3
user4

我想要做的是用我在该文件中拥有的所有用户创建一个列表框。我的第一个想法是:

Gui, Add, Button, , Log in
getUsers()
Gui, Show

getUsers()
{
    loop
    {
        FileReadLine, line, info.txt, %A_Index%
        if ErrorLevel
            Break
        Gui, Add, ListBox, cBlue, %line%
    }
}

但是并没有得到这个: Expected

我明白了: Reality

这完全有道理,但我怎样才能正确地做到这一点?我找不到任何附加选项。

您的代码看起来不错,但选项没有添加一行。相反,您必须声明 a

a pipe-delimited list

(见here

因此您的函数将连接一个字符串,然后将其添加到 gui 一次:

getUsers()
{
    choices := "" ; if you leave this line out, it'll work too I guess, but you might get a warning if #warn was set so
    loop
    {
        FileReadLine, line, info.txt, %A_Index%
        if ErrorLevel
            Break
        choices .= line "|"
    }
    Gui, Add, ListBox, cBlue, %choices%
}