Function for GUI visibility

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
OnlyMe
Posts: 9
Joined: 29 Mar 2020, 04:20

Function for GUI visibility

Post by OnlyMe » 27 Nov 2021, 07:08

Hello,

I'd like to convert the following code in a function:

Code: Select all

If !WinExist("ahk_class AutoHotkeyGUI")
Gui Show
else
Gui hide


GuiVisibility(){
If !WinExist("ahk_class AutoHotkeyGUI")
Gui show
else
Gui hide
}

This works perfectly of course
F1:: 
GuiVisibility()
but is it also possible to do something like this:

Code: Select all

GuiVisibility2(){
If !WinExist("ahk_class AutoHotkeyGUI")
return show
else
return  hide
}

Gui  % GuiVisibility2()
Can I express the keywords show and hide as function?

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

Re: Function for GUI visibility

Post by mikeyww » 27 Nov 2021, 12:04

Code: Select all

Gui, Color, Green
Gui, Add, Text, w300, Test1
F3::Gui, % toggleGUI()

toggleGUI(){
 Return WinExist("ahk_class AutoHotkeyGUI") ? "Hide" : "Show"
}
Or:

Code: Select all

Gui, New, +Hwndgui1
Gui, Color, Green
Gui, Add, Text, w300, Test1
F3::Gui, % gui1 ":" toggleGUI(gui1)

toggleGUI(hWnd){
 Return WinExist("ahk_id " hWnd) ? "Hide" : "Show"
}

Post Reply

Return to “Ask for Help (v1)”