We've got an AutoIt script to streamline our processes. The original version has been handed around and all were afraid to delete things, so I'm to rewrite it from scratch. The idea is to be a 'control panel' to launch some tasks. I'm trying to make it smaller and more streamlined so our on-the-floor techs can use it from tablets.
I'd like to create buttons that launch separate windows with the information the tech needs. The problem is trying to close the new windows when generated. I've got the second GUI to open, I just can't close it.
I tried variations of WinClose("title")
and WinKill("title")
, but neither work. They always end up locking the entire script. I'm using messageloop format, but I'm open to suggestions. My code:
#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
You need to use the advanced version of GUIGetMsg
in order to identify the window that has send the event. To do this you have to store the handle when you create the windows like this:
$hGuiMain = GUICreate(...)
$hGuiHelp = GUICreate(...)
$hGuiAbout = GUICreate(...)
Inside your main loop you are now able to test which window has send the event. If you know which window was triggered you can close the window or do whatever you want to do.
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