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

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
alawsareps
Posts: 26
Joined: 20 Jul 2016, 09:28

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

Post by alawsareps » 06 May 2024, 13:59

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")

User avatar
Seven0528
Posts: 393
Joined: 23 Jan 2023, 04:52
Location: South Korea
Contact:

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

Post by Seven0528 » 06 May 2024, 14:33

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
}
  • English is not my native language. Please forgive any awkward expressions.
  • 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.

niCode
Posts: 304
Joined: 17 Oct 2022, 22:09

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

Post by niCode » 06 May 2024, 15:24

Named parameters do not exist in AHK.

XMCQCX
Posts: 248
Joined: 14 Oct 2020, 23:44

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

Post by XMCQCX » 06 May 2024, 17:24

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.

User avatar
boiler
Posts: 17184
Joined: 21 Dec 2014, 02:44

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

Post by boiler » 08 May 2024, 06:10

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

Post Reply

Return to “Ask for Help (v2)”