Should not the Delete method be called when I set the instance to empty? (oGui := "")
Code: Select all
#Requires AutoHotkey v2
#SingleInstance Force
; Optional code to change the menu in the gui
; DllCall("dwmapi\DwmSetWindowAttribute", "ptr", A_ScriptHwnd, "int", 20, "int*", true, "int", 4)
; if VerCompare(A_OSVersion, "10.0.17763") >= 0 {
; attr := 19
; if VerCompare(A_OSVersion, "10.0.18985") >= 0 {
; attr := 20
; }
; DllCall("dwmapi\DwmSetWindowAttribute", "ptr", A_ScriptHwnd, "int", attr, "int*", true, "int", 4)
; }
; uxtheme := DllCall("GetModuleHandle", "str", "uxtheme", "ptr")
; SetPreferredAppMode := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 135, "ptr")
; FlushMenuThemes := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 136, "ptr")
; DllCall(SetPreferredAppMode, "int", 1) ; Dark
; DllCall(FlushMenuThemes)
class Gui_Log { ; object oriented GUI structure
;===============================================================================
__New(WinTitle:="Log",W:=800, H:=200, x := "Center", y := "Center"){ ; constructor
static
; Building the Gui
this.myGui := Gui(,WinTitle)
this.myGui.BackColor := 0x0C0C0C
this.MyGui.SetFont("s11 cCCCCCC", "Consolas")
this.myGui.x := x
this.myGui.y := y
this.myGui.Opt("+LastFound +AlwaysOnTop +Border +Resize")
this.myGui.OnEvent("Size",(p*)=>(this.Gui_Size(p*)))
This.EControl := This.myGui.AddEdit("x0 y0 h" H " w" W " -E0x200 +ReadOnly")
This.EControl.Opt("Background0x0C0C0C cCCCCCC")
DllCall("dwmapi\DwmSetWindowAttribute", "ptr", This.myGui.hwnd, "int", 20, "int*", true, "int", 4)
DllCall("uxtheme\SetWindowTheme", "ptr", This.EControl.hwnd, "str", "DarkMode_Explorer", "ptr", 0)
this.myGui.Show("x" this.myGui.x " y" this.myGui.y)
this.Gui_Size()
Return
}
SetProgress(Value:=0, ProgressText?){
This.Show()
this.myGui.GetClientPos(&X, &Y, &Width, &Height)
This.Progress := Value
if (!This.HasProp("CProgress")){
This.CProgress := This.myGui.AddText("x0 y0 w" Width*This.Progress/100 " h16 Background0x4D4D4D")
This.EControl.Move(,16,Width, Height-16)
This.ProgressText := This.myGui.AddText("x0 y0 w" Width " h16 +0x200 +Center +BackgroundTrans", ProgressText ?? "")
} else {
(IsSet(ProgressText)) ? (This.ProgressText.Text := ProgressText) : ""
This.CProgress.Move(,,Width*This.Progress/100)
This.ProgressText.Move(0,0,Width)
}
This.ProgressText.Redraw()
}
Show(){
this.myGui.Show()
}
Gui_Size(*){
this.myGui.GetClientPos(&X, &Y, &Width, &Height)
This.EControl.GetPos(&x, &y, &w, &h)
if (This.HasProp("CProgress")){
This.CProgress.Move(,,Width*This.Progress/100)
This.ProgressText.Move(0,0,Width)
}
This.EControl.Move(,,Width, Height-y)
}
AddLine(Line, newline:=true, ReplaceLastLine:=false){
delimiter:="`r`n"
if (This.EControl.Text="" or !newline){
delimiter := ""
}
if (ReplaceLastLine){
TextWithoutLastLine := RegExReplace(This.EControl.Text, "(.*)\r\n.*$", "$1",&OutputVarCount) ; Remove the last line
TextWithoutLastLine := (OutputVarCount=0) ? "" : TextWithoutLastLine delimiter
This.EControl.Text := TextWithoutLastLine Line
ControlSend("^{end}", , This.EControl)
return
}
ControlSend("^{end}", , This.EControl)
EditPaste(delimiter Line,This.EControl)
}
__Delete(){
this.myGui.Destroy()
}
Delete(){
this.myGui.Destroy()
}
Destroy(){
this.myGui.Destroy()
}
}
oGui := Gui_Log()
NumberLoops := 5
loop NumberLoops
{
oGui.SetProgress(A_Index*100/NumberLoops,Round(A_Index*100/NumberLoops) "/100")
oGui.AddLine("This Program will close in " 6-A_Index " Seconds...")
sleep(500)
}
oGui := ""