I would like to have different functions to perform different tasks:
GuiMainLoad() ;Adds controls to GUI etc
GuiMainShow() ;Shows/hides GUI
GuiMainEvents() ;takes care of control events (gLabel)
GuiMainLoad() is responsible for creating all the GUI controls and so their respective associated variables must be defined as static variables within GuiMainLoad(), but then GuiMainEvents() has no awareness of those static variables because they live in a different function, so what's the use of static variables here?
The only solution I could think of is to put everything inside one multi-purpose function that does different things depending on the parameters passed, but it seems too convoluted:
Code: Select all
#NoEnv
#SingleInstance Force
Global Action_Load := 1
Global Action_Show := 2
GuiMainLoad()
GuiAuxLoad()
GuiMainShow()
GuiAuxShow()
Return
Gui_Main(Action := 0)
{
Static
Gui, Main:Default
If (Action = Action_Init)
{
Gui, Font, s16
Gui, Add, Edit, vEdit gGui_Main x10 y10 w200 , hello world
Gui, Add, Button, vMyButton1 gGui_Main x10 y50 w200 h40, Button 1
Gui, Add, Button, vMyButton2 gGui_Main x10 y100 w200 h40, Button 2
Gui, +AlwaysOnTop
}
Else If (Action = Action_Show)
{
Gui, Show,, MAIN
}
Else ;Control actions (Action = 0)
{
If (A_GuiControl = "MyButton1")
{
Tooltip You pressed Button 1 on MAIN
}
Else If (A_GuiControl = "MyButton2")
{
Tooltip You pressed Button 2 on MAIN
}
Else If (A_GuiControl = "MyEdit")
{
Tooltip You are typing text in Edit box on MAIN
}
}
}
Gui_Aux(Action := 0)
{
Static
Gui, Aux:Default
If (Action = Action_Init)
{
Gui, Font, s16
Gui, Add, Edit, vMyEdit gGui_Aux x10 y10 w200 , hello world
Gui, Add, Button, vMyButton1 gGui_Aux x10 y50 w200 h40, Button 1
Gui, Add, Button, vMyButton2 gGui_Aux x10 y100 w200 h40, Button 2
Gui, +AlwaysOnTop
}
Else If (Action = Action_Show)
{
Gui, Show,, AUX
}
Else ;Control actions (Action = 0)
{
If (A_GuiControl = "MyButton1")
{
Tooltip You pressed Button 1 on AUX
}
Else If (A_GuiControl = "MyButton2")
{
Tooltip You pressed Button 2 on AUX
}
Else If (A_GuiControl = "MyEdit")
{
Tooltip You are typing text in Edit box on AUX
}
}
}
GuiMainInit()
{
Gui_Main(Action_Init)
}
GuiMainShow()
{
Gui_Main(Action_Show)
}
GuiAuxInit()
{
Gui_Aux(Action_Init)
}
GuiAuxShow()
{
Gui_Aux(Action_Show)
}