Hi
@TheArkive
Your suggestion works well. Thanks.
Here is a bare minimum replica of a V1 script that I use during monsoon.
Code: Select all
#Warn
#SingleInstance
;Loop 1000
rfCalc()
f2::rfCalc()
rfCalc() { ; Rainfall calculator for AutoHotkey 2.0-beta.1
; by SKAN on D481/D482 @ __
Local Glob
Local H, Y, GroupBox1, MyGui
Local Font := Map( "TextItalic", ["s11 Norm Italic", "Calibri"]
, "TextUnderL", ["s11 Norm Underline", "Calibri"]
, "TextNormal", ["s11 Norm", "Consolas"]
, "MonoNormal", ["s12 Norm", "Consolas"] )
MyGui := Gui("-Theme -MinimizeBox", "Rainfall calculator")
Glob := Map(1,0, 2,0, 3,0, 4,0)
MyGui.MyProp := ObjPtrAddRef(Glob)
MyGui.MarginX := 16
MyGui.MarginY := 8
MyGui.SetFont(Font["TextItalic"]*)
GroupBox1 := MyGui.Add("GroupBox", "xm ym w180 h120", " Parameters ")
MyGui.SetFont(Font["TextUnderL"]*)
MyGui.Add("Text", "xp+16 yp+24 w148 Section Right", " Diameter of collector")
MyGui.SetFont(Font["MonoNormal"]*)
Glob[1] := MyGui.Add("Edit", "xs y+0 wp-24 h18 -E0x200 Right")
MyGui.SetFont(Font["TextNormal"]*)
MyGui.Add("Text", "x+0 yp w24 hp 0x200 Right", "cm")
MyGui.SetFont(Font["TextUnderL"]*)
MyGui.Add("Text", "xs y+12 w148 Right", " 1 cm rainfall equals to")
MyGui.SetFont(Font["MonoNormal"]*)
Glob[2] := MyGui.Add("Edit", "xs y+0 wp-24 h18 -E0x200 Right")
MyGui.SetFont(Font["TextNormal"]*)
MyGui.Add("Text", "x+0 yp w24 0x200 Right", "ml")
GroupBox1.GetPos(,,,&H), Y := (MyGui.MarginY * 2) + H ; adjusted Y pos for DPI scaling
MyGui.SetFont(Font["TextItalic"]*)
MyGui.Add("GroupBox", "xm w180 h120 y" Y, " Calculation ")
MyGui.SetFont(Font["TextUnderL"]*)
MyGui.Add("Text", "xp+16 yp+24 w148 Section Right", " Collected rain")
MyGui.SetFont(Font["MonoNormal"]*)
Glob[3] := MyGui.Add("Edit", "xs y+0 wp-24 h18 -E0x200 Right")
MyGui.SetFont(Font["TextNormal"]*)
MyGui.Add("Text", "x+0 yp w24 0x200 Right", "ml")
MyGui.SetFont(Font["TextUnderL"]*)
MyGui.Add("Text", "xs y+12 w148 Right", " Rainfall")
MyGui.SetFont(Font["MonoNormal"]*)
Glob[4] := MyGui.Add("Edit", "xs y+0 wp-24 h18 -E0x200 Right")
MyGui.SetFont(Font["TextNormal"]*)
MyGui.Add("Text", "x+0 yp w24 0x200 Right", "cm")
Glob[1].OnEvent( "Change", rfCalc_EditRoutine.Bind(Glob, Glob[1].Hwnd) )
Glob[2].OnEvent( "Change", rfCalc_EditRoutine.Bind(Glob, Glob[2].Hwnd) )
Glob[3].OnEvent( "Change", rfCalc_EditRoutine.Bind(Glob, Glob[3].Hwnd) )
Glob[4].OnEvent( "Change", rfCalc_EditRoutine.Bind(Glob, Glob[4].Hwnd) )
Glob[1].Value := IniRead(A_ScriptDir "\rfCalc.ini", "rfCalc", "Dia", "")
Glob[2].Value := IniRead(A_ScriptDir "\rfCalc.ini", "rfCalc", "Vol", "")
If Glob[2].Value
Glob[3].Focus()
MyGui.OnEvent("Close", rfCalc_Close)
MyGui.OnEvent("Escape", rfCalc_Close)
MyGui.Show("AutoSize")
}
rfCalc_Close(MyGui) {
Local Glob := ObjFromPtr( MyGui.MyProp )
IniWrite(Glob[1].Value, A_ScriptDir "\rfCalc.ini", "rfCalc", "Dia")
IniWrite(Glob[2].Value, A_ScriptDir "\rfCalc.ini", "rfCalc", "Vol")
MyGui.DeleteProp("MyProp") ; Is necessary?
Glob := "" ; Is necessary?
MyGui.Destroy()
}
rfCalc_EditRoutine(Glob, Hwnd, *) {
Static PI := 3.14159265358979
Local R, Rmm, Dia, Vol, Col
Switch( Hwnd )
{
Case Glob[1].Hwnd :
{
If ! IsNumber( Dia := Glob[1].Value )
Return
R := Dia/2
Vol := PI * R * R
Glob[2].Value := Round(Vol, 6)
Glob[3].Value := ""
Glob[4].Value := ""
}
Case Glob[2].Hwnd :
{
If ! IsNumber( Vol := Glob[2].Value )
Return
Vol := Glob[2].Value
Dia := Sqrt(Vol/PI) * 2
Glob[1].Value := Round(Dia, 6)
Glob[3].Value := ""
Glob[4].Value := ""
}
Case Glob[3].Hwnd :
{
If ! IsNumber( Dia := Glob[1].Value )
|| ! IsNumber( Vol := Glob[2].Value )
|| ! IsNumber( Col := Glob[3].Value )
Return
Glob[4].Value := Round(Col/Vol, 4 )
}
Case Glob[4].Hwnd :
{
If ! IsNumber( Dia := Glob[1].Value )
|| ! IsNumber( Vol := Glob[2].Value )
|| ! IsNumber( Rmm := Glob[4].Value )
Return
Glob[3].Value := Round(Vol*Rmm, 4 )
}
} ; end switch
}
Experts let me know if I am doing something wrong.
If I start off with a single GUI, the memory usage is like 1.5 MiB to 2.0 MiB
If I start off with 1000 GUI's the memory usage is like (mere) 18 MiB.
But when I close them all and return to a single GUI, the memory usage is like 4.0 MiB.
Am I leaking something?
PS: I don't need 1000 GUI's but I intend to put many such tiny apps into a single always-running-script.
So, all GUI need to cleanly exit.