Hide or Destroy the previous Instance of a Gui Window Created Through a Function Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
jsong55
Posts: 263
Joined: 30 Mar 2021, 22:02

Hide or Destroy the previous Instance of a Gui Window Created Through a Function

12 Apr 2023, 08:03

Code: Select all

QuickCopyLaunch(QuickCopyContents)                                                                                               
{
    ; if (qc.Hwnd)
    ;     qc.Destroy()
    qc:=Gui()
    qc.Add("Edit","xm y+0" " w500 r10" " vQuickCopyContents",QuickCopyContents)
    qc.show()
}
Running the function repeatedly causes endless Guis
jsong55
Posts: 263
Joined: 30 Mar 2021, 22:02

Re: Hide or Destroy the previous Instance of a Gui Window Created Through a Function

12 Apr 2023, 09:02

How to destroy old instance and create a new instance within the same function creating it?
RussF
Posts: 1303
Joined: 05 Aug 2021, 06:36

Re: Hide or Destroy the previous Instance of a Gui Window Created Through a Function

12 Apr 2023, 09:40

Perhaps it would be easier to post exactly what it is that you're trying to accomplish. Why would you call the function multiple times without closing the previous one first?

I'm usually not a fan of creating GUIs from within a function. I will typically define them outside the function within the autoexec section of the script and then call MyGui.Show() and/or MyGui.Hide() from within the function. That way, there is only one copy of the GUI in memory at any one time.

Russ
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Hide or Destroy the previous Instance of a Gui Window Created Through a Function  Topic is solved

12 Apr 2023, 10:09

u can keep the existing reference around in a static variable

Code: Select all

#Requires AutoHotkey v2.0.2

QuickCopyLaunch(QuickCopyContents)                                                                                               
{
	static qc

	if IsSet(qc)
		qc.Destroy()

    qc:=Gui()
    qc.Add("Edit","xm y+0" " w500 r10" " vQuickCopyContents",QuickCopyContents)
    qc.show()
}
RussF
Posts: 1303
Joined: 05 Aug 2021, 06:36

Re: Hide or Destroy the previous Instance of a Gui Window Created Through a Function

12 Apr 2023, 11:24

Thanks @swagfag, I wasn't sure if you could do that with an object and didn't have time to test it (I'm supposed to be working, you know :shh: )

Russ

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Draken, Insaid, RussF and 31 guests