Page 1 of 1

Best Way to control another gui

Posted: 07 Jun 2023, 01:54
by Spitzi
Hi there.

I wonder what the best way is to control one gui from another. Say I want to close a gui when hitting a button on another.

I created global variables for every gui object that I need to access, and then use

Code: Select all

Try GuiObj.Destroy()
to close it.

Is there another way of accessing the guis without using global variables. A list of guis that are running, that I am not aware of.

Re: Best Way to control another gui

Posted: 07 Jun 2023, 06:00
by mikeyww

Code: Select all

#Requires AutoHotkey v2.0
gui1 := Gui(, 1)
gui2 := Gui(, 2)
gui1.AddButton('w230', 'Close').OnEvent('Click', close_Click)
gui2.AddButton('w230', 'Close').OnEvent('Click', close_Click)
gui1.Show 'x200'
gui2.Show

close_Click(btn, info) {
 For each, hWnd in WinGetList('ahk_class AutoHotkeyGUI')
  If hWnd != btn.Gui.Hwnd
   WinClose hWnd
}

Re: Best Way to control another gui

Posted: 15 Jun 2023, 07:30
by Spitzi
Thanks @mikeyww that's helpful.

What is the quickest way to get the guiObject when the Window Hwnd is known? Is there an array of all running guis?

Greets Spitzi

Re: Best Way to control another gui

Posted: 15 Jun 2023, 07:31
by Spitzi