[SOLVED] GUI OnClose()

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

[SOLVED] GUI OnClose()

14 Dec 2019, 03:27

First a simple code:

Code: Select all

(gui:= GuiCreate())
	.OnEvent("Close", "gui_OnClose")
gui.Add("Text",, "Press Enter")
gui.Add("Button","Default w0 h0")
	.OnEvent("Click", "btn_OnClick")
gui.Show()	

gui_OnClose(*) {
	return MsgBox("Enter for Close",, "OC") == "Cancel"
}

btn_OnClick(*) {
	global
	gui.Hide() ; <<< Close without asking ???
}
I don`t understand why gui.Hide() "close" gui without calling OnClose?
I understand that this function corresponding to EVENT "OnClose", in true GUI have "CLOSE" procedure that is unavailable or undocumented.
In other words WHEN "Close" EVENT then call OnEvent function, but this is not "CLOSE" procedure it is "IF" to do close or not. So I think it is logically OnClose to be called any time when GUI start CLOSE.
The only way I found:

Code: Select all

btn_OnClick(*) {
	global
	Send("!{F4}")
	;gui.Hide() ; <<< Close without asking ???
}
YEP:
Gui.Close() is just WinClose(Gui)

Code: Select all

btn_OnClick(*) {
	global
	WinClose(gui)
}
Last edited by _3D_ on 14 Dec 2019, 07:35, edited 1 time in total.
AHKv2.0 alpha forever.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: GUI OnClose()

14 Dec 2019, 06:12

because hiding a window does just that - it hides it. it doesnt close the window. therefore, no onClose callbacks are invoked

Code: Select all

btn_OnClick(Btn, *) {
	WinClose(Btn.Gui)
}
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

Re: [SOLVED] GUI OnClose()

14 Dec 2019, 07:37

AHKv2.0 alpha forever.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Draken, mikeyww and 30 guests