【问题标题】:Create multiple GUIs创建多个 GUI
【发布时间】:2014-08-26 19:26:06
【问题描述】:

我们有一个 AutoIt 脚本来简化我们的流程。原版已经传出去了,大家都不敢删东西,所以我要从头重写。这个想法是成为一个“控制面板”来启动一些任务。我正在努力让它更小、更精简,以便我们的现场技术人员可以在平板电脑上使用它。

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

我尝试了WinClose("title")WinKill("title") 的变体,但都不起作用。他们总是最终锁定整个脚本。我正在使用消息循环格式,但我愿意接受建议。我的代码:

#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

【问题讨论】:

    标签: user-interface autoit


    【解决方案1】:

    您需要使用高级版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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-17
      • 1970-01-01
      • 1970-01-01
      • 2015-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多