there are several ways to hook up events in v2. one is by defining a function that would handle the event and providing a reference to it to .OnEvent()
Code: Select all
#Requires AutoHotkey v2.0-a131-2327728b
G := Gui()
G.OnEvent('DropFiles', Gui_DropFiles)
Gui_DropFiles(GuiObj, GuiCtrlObj, FileArray, X, Y) {
MsgBox(FileArray.Length ' file(s) dropped.')
}
G.Show('w200 h200')
another is by specifying an EventSinkObj and passing the name of an instance method of the specified EventSinkObj as a string to .OnEvent()
Code: Select all
#Requires AutoHotkey v2.0-a131-2327728b
G := MyGui()
class MyGui extends Gui {
__New() {
super.__New('', '', this)
this.OnEvent('DropFiles', 'Gui_DropFiles')
this.Show('w200 h200')
}
Gui_DropFiles(GuiCtrlObj, FileArray, X, Y) {
MsgBox(FileArray.Length ' file(s) dropped.')
}
}
problem: if u drop files on the EventSink example, the script crashes once the event handler callback starts going out of scope
solution: linked code needs adjusted to account for the shift in the handler's parameters(so it doesnt keep trying to cast X - an integer, to an object and call ->Release() on it)