Best Way to control another gui

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Spitzi
Posts: 309
Joined: 24 Feb 2022, 03:45

Best Way to control another gui

Post by Spitzi » 07 Jun 2023, 01:54

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.

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Best Way to control another gui

Post by mikeyww » 07 Jun 2023, 06:00

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
}

Spitzi
Posts: 309
Joined: 24 Feb 2022, 03:45

Re: Best Way to control another gui

Post by Spitzi » 15 Jun 2023, 07:30

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


Post Reply

Return to “Ask for Help (v2)”