Static variables for GUI control associated variables?
Posted: 18 Sep 2018, 16:57
I''m working on a script which contains several GUIs each having many controls. I don't want to use global variables for control associated variables, instead I'd like to use static variables, but I can't fathom how I should go about it.
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:
Is there a proper way to do this? Thanks
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)
}