创建多个GUI

时间:2014-08-26 19:26:06

标签: user-interface autoit

我们有一个AutoIt脚本来简化我们的流程。原始版本已被传递,并且所有人都害怕删除内容,所以我要从头开始重写它。我们的想法是成为一个“控制面板”。发起一些任务。我试图让它变得更小,更精简,所以我们的现场技术人员可以在平板电脑上使用它。

我想创建按钮,用技术所需的信息启动单独的窗口。问题是在生成时尝试关闭新窗口。我已经打开了第二个GUI,我无法关闭它。

我尝试了WinClose("title")WinKill("title")的变体,但都没有奏效。他们总是最终锁定整个脚本。我使用的是messageloop格式,但我愿意接受建议。我的代码:

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <windowsConstants.au3>
#include <ColorConstants.au3>

;Button Declarations
Global $List

;GUI Creation
Opt('MustDeclarVars', 1) ;Creates an error message if a variable is used by not declared.
GUICreate("Tech Control Panel", 450, 530) ;Creates the GUI and it's elements.
GUISetState(@SW_SHOW)

;Button creation and location settings
;Left Column
GUICtrlCreateLabel("Tools", 10, 10, 100, 30, $SS_CENTER)
$List = GUICtrlCreateButton("Tech List", 10, 30, 100, 30)

;Main loop, gets GUI actions and processes them
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $TechList
            GUICreate("List", 200, 300)
            GUISetState(@SW_SHOW)
            While 1
                $msg = GUIGetMsg()
                Select
                    Case $msg = $GUI_Event_Close
                        WinClose("List")
                EndSelect
            WEnd
        Case $msg = $GUI_Event_Close
            Exit
    EndSelect
WEnd

1 个答案:

答案 0 :(得分:0)

您需要使用GUIGetMsg的高级版本来识别发送事件的窗口。为此,您必须在创建窗口时存储句柄,如下所示:

$hGuiMain = GUICreate(...)
$hGuiHelp = GUICreate(...) 
$hGuiAbout = GUICreate(...)

在主循环中,您现在可以测试哪个窗口发送了该事件。如果你知道触发了哪个窗口,你可以关闭窗口或做你想做的任何事情。

While 1
    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $hGuiMain
            If $aMsg[0] = $GUI_EVENT_CLOSE Or $aMsg[0] = $mnuFileExit Then
                ExitLoop
            EndIf
        Case $hGuiHelp
            If $aMsg[0] = $GUI_EVENT_CLOSE Then
                GUISetState(@SW_ENABLE, $hGuiMain)
                GUIDelete($hGuiHelp)
            EndIf
        Case $hGuiAbout
            If $aMsg[0] = $GUI_EVENT_CLOSE Then
                GUISetState(@SW_ENABLE, $hGuiMain)
                GUIDelete($hGuiAbout)
            EndIf
    EndSwitch
WEnd
相关问题