Is possible to bind an action to a GUI button?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
fabricio234
Posts: 122
Joined: 06 Mar 2020, 21:48

Is possible to bind an action to a GUI button?

12 Jun 2022, 12:00

I know its possible to bind a call to function or a label

Code: Select all

gui, add, button, hWndbut vbut, minimize
onclick := ObjBindMethod("WinMinimize", "")
GuiControl, +g, %but%, %onclick%

gui, show, w300 h100
Return

WinMinimize() {
   WinMinimize, A
}

Is it possible to execute the function directly? something like this:

Code: Select all

gui, add, button, hWndbut vbut, minimize
onclick := ObjBindMethod("WinMinimize", "A")
GuiControl, +g, %but%, %onclick%

gui, show, w300 h100
return
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Is possible to bind an action to a GUI button?

12 Jun 2022, 12:04

Use func + bind instead of :arrow: ObjBindMethod. Example,

Code: Select all

Gui, Add, Button, hWndbut vbut, minimize
onclick := func("f").bind("abc")
GuiControl, +g, %but%, %onclick%

Gui, Show, w300 h100
Return

f(x){
	msgbox % x
}
WinMinimize isn't a function, but a command. So you cannot use it with func directly. You can call it from a user defined function instead.
Cheers.
fabricio234
Posts: 122
Joined: 06 Mar 2020, 21:48

Re: Is possible to bind an action to a GUI button?

12 Jun 2022, 14:58

Helgef wrote:
12 Jun 2022, 12:04
Use func + bind instead of :arrow: ObjBindMethod
Just for clarification, there's any problem using objbindmethod? is it wrong or what?
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Is possible to bind an action to a GUI button?

13 Jun 2022, 01:50

It is wrong in this case, yes. See the documentation I linked to. ObjBindMethod takes an object as its first parameter, a method names as its second, subsequent parameters are values to bind to the method's remaining parameters. Here is how you could use ObjBindMethod, in your case,

Code: Select all

Gui, Add, Button, hWndbut vbut, minimize

obj := func("f")				; the object
onclick := objBindMethod(obj	
	, "call"					; the method name
	, "abc")					; the value to bind to the first parameter

GuiControl, +g, %but%, %onclick%

Gui, Show, w300 h100
Return

f(x){
	msgbox % x
}
Ofc, this is unnecessarily complex, just use func + bind.

Cheers.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Kodakku and 367 guests