在AutoHotKey中循环GUI界面

时间:2013-11-30 06:57:57

标签: loops user-interface macros key autohotkey

我试图使用AutoHotKey创建一个宏,并且我试图让循环创建与用户指定的GUI一样多的GUI,唯一的问题是当在“OK:”行之后调用“return”时,GUI退出循环以及当前的GUI。因此,循环仅在整个应用程序退出之前第一次运行?

我的代码如下,任何帮助将不胜感激!谢谢!

n = 0
Loop:
{
n := n + 1

    Gui, Add, Button, x1 y174 w110 h40 gOK, Button
    Gui, Add, Text, x1 y34 w90 h20 , City #%n% Name:
    Gui, Add, Edit, x91 y34 w200 h20 vCity, Edit
    Gui, Add, Text, x1 y84 w60 h20 , Farm 1
    Gui, Add, Edit, x61 y84 w70 h20 vFarm1, Edit
    Gui, Add, Text, x1 y134 w60 h20 , Farm 2
    Gui, Add, Edit, x61 y134 w70 h20 vFarm2, Edit
    Gui, Add, Edit, x221 y84 w80 h20 vFarm3, 807`, 341
    Gui, Add, Edit, x221 y134 w80 h20 vFarm4, Edit
    Gui, Add, Text, x151 y84 w70 h20 , Farm 3
    Gui, Add, Text, x151 y134 w70 h20 , Farm 4
    Gui, Add, Text, x321 y84 w70 h20 , Text
    Gui, Add, Edit, x391 y84 w80 h20 vFarm5, Edit
    Gui, Add, Text, x321 y134 w70 h20 , Text
    Gui, Add, Edit, x391 y134 w80 h20 vFarm6, Edit
    Gui, Add, Text, x491 y84 w70 h20 , Text
    Gui, Add, Edit, x581 y84 w80 h20 vFarm7, Edit
    Gui, Add, Text, x491 y134 w70 h20 , Text
    Gui, Add, Edit, x581 y134 w80 h20 vFarm8, Edit
    Gui, Show, x321 y200 h257 w745, GrepoFarm  ~~~~~ Hockeyman271 ~~~~~~
    return

    GuiClose:
        ExitApp
        return

    Ok: ; label triggered by the button
        Gui, submit, nohide ; hide or nohide depends on what you want

        FileCreateDir, %A_WorkingDir%\Data\%City%
            if ErrorLevel
                MsgBox ERROR Creating Directory for "%City%"

        FileAppend, %City%, %A_WorkingDir%\Data\%City%\city.txt
        FileAppend, %Farm1%, %A_WorkingDir%\Data\%City%\farm1.txt
        FileAppend, %Farm2%, %A_WorkingDir%\Data\%City%\farm2.txt
        FileAppend, %Farm3%, %A_WorkingDir%\Data\%City%\farm3.txt
        FileAppend, %Farm4%, %A_WorkingDir%\Data\%City%\farm4.txt
        FileAppend, %Farm5%, %A_WorkingDir%\Data\%City%\farm5.txt
        FileAppend, %Farm6%, %A_WorkingDir%\Data\%City%\farm6.txt
        FileAppend, %Farm7%, %A_WorkingDir%\Data\%City%\farm7.txt
        FileAppend, %Farm8%, %A_WorkingDir%\Data\%City%\farm8.txt

    Gui, Destroy
    return
}

1 个答案:

答案 0 :(得分:1)

啊,从它的外观来看,你做错了很少。 而且,如果我没有记错,你可能只创建一个GUI!循环运行,所有控件都添加到同一GUI。如果您添加gui, show,您会看到。

另外,不要将你的返回放在循环中,否则循环将停止 - 这将解释为什么你的循环在创建一个GUI后退出。

尝试这样的事情:

n = 1
Loop:
{
    gosub, BuildNewForm
    n++ 
}

BuildNewForm:
    Gui, GrepoFarm%n%:new           ;name the gui with it's number to keep the GUI's different
    Gui, Add, Button, x1 y174 w110 h40 gOK, Button
    Gui, Show, x321 y200 h257 w745, GrepoFarm  ~~~~~ Hockeyman271 ~~~~~~
return

GuiClose:
    ExitApp
return

;other subs and functions