It would be kind of nice to be able to use methods directly for callbacks without having to code a dummy function outside the class (that calls the method...).
For completeness: What also doesn't work right now is to register a bound func object created with func().Bind(), but I can't really think of a practical case where I would want to override parameters of the callback function...
The code below illustrates the current situation.
Many thanks,
Elgin
Code: Select all
WT:=new WinTest()
WT.StartF() ; use the func object for EnumWindowsProc
WT.Show() ; works
WT.StartFB() ; use the boundfunc object for EnumWindowsProc
WT.Show() ; does not work
WT.StartO() ; use the method EnumWindowsProc
WT.Show() ; does not work
return
EnumWindowsProcE(hwnd, lParam)
{
global EnumMethod
return %EnumMethod%(hwnd, lParam)
}
class WinTest
{
Output:=""
StartF()
{
global EnumMethod
this.Output:=""
EnumMethod:=ObjBindMethod(this, "EnumWindowsProc")
EnumAddress := RegisterCallback(Func("EnumWindowsProcE"), "Fast")
DllCall("EnumWindows", Ptr, EnumAddress, Ptr, 0)
}
StartFB()
{
global EnumMethod
this.Output:=""
EnumMethod:=ObjBindMethod(this, "EnumWindowsProc")
EnumAddress := RegisterCallback(Func("EnumWindowsProcE").Bind(WinExist("A")), "Fast")
DllCall("EnumWindows", Ptr, EnumAddress, Ptr, 0)
}
StartO()
{
this.Output:=""
EnumAddress := RegisterCallback(ObjBindMethod(this, "EnumWindowsProc"), "Fast")
DllCall("EnumWindows", Ptr, EnumAddress, Ptr, 0)
}
EnumWindowsProc(hwnd, lParam)
{
WinGetTitle, title, ahk_id %hwnd%
WinGetClass, class, ahk_id %hwnd%
if title
this.Output .= "HWND: " . hwnd . "`tTitle: " . title . "`tClass: " . class . "`n"
return true ; Tell EnumWindows() to continue until all windows have been enumerated.
}
Show()
{
msgbox, % this.output
}
}