Page 1 of 1

Is it possible to pass named parameters? e.g. create_GUI(name: "status_GUI", bgcolor: "blue")

Posted: 06 May 2024, 13:59
by alawsareps

Code: Select all

#Requires AutoHotkey v2.0

create_GUI(name_GUI, text_GUI, bgcolor) {
name_GUI := Gui()
name_GUI.Opt("-Caption +ToolWindow +AlwaysOnTop")
name_GUI.BackColor := bgcolor
name_GUI.Add("Text", , text)
name_GUI.Show("x880 y900 NoActivate")
}

create_GUI(name_GUI: "status_GUI", text: "hello", bgcolor: "blue")

Re: Is it possible to pass named parameters? e.g. create_GUI(name: "status_GUI", bgcolor: "blue")

Posted: 06 May 2024, 14:33
by Seven0528

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force
#Warn VarUnset, Off

createGuiByString("a")
a.show("x10 y10 w240 h240")
createGuiByReference(&b)
b.show("x20 y20 w240 h240")
createGui("c")
c.show("x30 y30 w240 h240")
createGui(&d)
d.show("x40 y40 w240 h240")

createGuiByString(guiName)    {
    global
    %guiName% := gui()
}
createGuiByReference(&guiRef)    {
    guiRef := gui()
}
createGui(param)    {
    global
    if (param is VarRef) || (param is String)    {
        %param% := gui()
        return true
    }
    return false
}

Re: Is it possible to pass named parameters? e.g. create_GUI(name: "status_GUI", bgcolor: "blue")

Posted: 06 May 2024, 15:24
by niCode
Named parameters do not exist in AHK.

Re: Is it possible to pass named parameters? e.g. create_GUI(name: "status_GUI", bgcolor: "blue")

Posted: 06 May 2024, 17:24
by XMCQCX
I've just shared the script I use to create notification GUIs. Feel free to check it out.
viewtopic.php?f=83&t=129635

Features
  • Changing text, icon, font, color etc.
  • Positioning at different locations on the screen.
  • Duration before it disappears.
  • Playing sound when it appears.
  • Call function when clicking on it.

Re: Is it possible to pass named parameters? e.g. create_GUI(name: "status_GUI", bgcolor: "blue")

Posted: 08 May 2024, 06:10
by boiler
This is very close to what you said you are looking to do, and the order doesn't matter (the advantage of named parameters), as the second GUI shows:

Code: Select all

#Requires AutoHotkey v2.0
status_GUI := create_GUI({name_GUI: "status_GUI", text: "hello", bgcolor: "blue", opt: "x880 y900 NoActivate"})
other_GUI := create_GUI({name_GUI: "other_GUI", bgcolor: "green", opt: "x880 y950 NoActivate", text: "goodbye"})

create_GUI(g) { ; name_GUI, text_GUI, bgcolor
	g.name_GUI := Gui()
	g.name_GUI.Opt("-Caption +ToolWindow +AlwaysOnTop")
	g.name_GUI.BackColor := g.bgcolor
	g.name_GUI.Add("Text", , g.text)
	g.name_GUI.Show(g.Opt)
	return g.name_GUI
}

; alernately flash the GUIs
loop 5 {
	Sleep 500
	status_GUI.Show
	other_GUI.Hide
	Sleep 500
	status_GUI.Hide
	other_GUI.Show
}
ExitApp