| SuperStrict Local x:Int=(GadgetWidth(Desktop())-400)/2 Local y:Int=(GadgetHeight(Desktop())-400)/2 Local MyWindow:TGadget=CreateWindow("EventHook Example", x,y,400,400) Global MyCanvas:TGadget=CreateCanvas(0,0,380,360,MyWindow) Local SmallWindow:TGadget=CreateWindow("Move Me", x+125, y+150, 150, 100, MyWindow, WINDOW_TITLEBAR) Repeat WaitEvent() Select EventID() Case EVENT_WINDOWCLOSE End Case EVENT_GADGETPAINT UpDateCanvas() End Select Forever End Function UpdateCanvas:Int() SetGraphics CanvasGraphics(MyCanvas) Cls SetColor Rnd(255),Rnd(255),Rnd(255) DrawRect 10,10,100,150 Flip End Function |
![]() |
![]() |
| Local x:Int=(GadgetWidth(Desktop())-400)/2 Local y:Int=(GadgetHeight(Desktop())-400)/2 |
| Local MyWindow:TGadget=CreateWindow("EventHook Example", x,y,400,400) Global MyCanvas:TGadget=CreateCanvas(0,0,380,360,MyWindow) Local SmallWindow:TGadget=CreateWindow("Move Me", x+125, y+150, 150, 100, MyWindow, WINDOW_TITLEBAR) |
| Repeat WaitEvent() Select EventID() Case EVENT_WINDOWCLOSE End Case EVENT_GADGETPAINT UpDateCanvas() End Select Forever End |
| Function UpdateCanvas:Int() SetGraphics CanvasGraphics(MyCanvas) Cls SetColor Rnd(255),Rnd(255),Rnd(255) DrawRect 10,10,100,150 Flip End Function |
| SuperStrict Local x:Int=(GadgetWidth(Desktop())-400)/2 Local y:Int=(GadgetHeight(Desktop())-400)/2 Local MyWindow:TGadget=CreateWindow("EventHook Example", x,y,400,400) Global MyCanvas:TGadget=CreateCanvas(0,0,380,360,MyWindow) Local SmallWindow:TGadget=CreateWindow("Move Me", x+125, y+150, 150, 100, MyWindow, WINDOW_TITLEBAR) AddHook EmitEventHook, MyHook Repeat WaitEvent() Select EventID() Case EVENT_WINDOWCLOSE End Case EVENT_GADGETPAINT UpDateCanvas() End Select Forever End Function MyHook:Object(iId:Int,tData:Object,tContext:Object) Local Event:TEvent=TEvent(tData) If Event.source=MyCanvas And Event.ID=EVENT_GADGETPAINT UpdateCanvas() Return Null EndIf Return tData End Function Function UpdateCanvas:Int() SetGraphics CanvasGraphics(MyCanvas) Cls SetColor Rnd(255),Rnd(255),Rnd(255) DrawRect 10,10,100,150 Flip End Function |
![]() |
![]() |
| AddHook EmitEventHook, MyHook |
| Function AddHook( id,func:Object( id,data:Object,context:Object ),context:Object=Null,priority=0 ) |
| Function AddHook( id,func) |
| Function MyHook:Object(iId:Int,tData:Object,tContext:Object) |
| Local Event:TEvent=TEvent(tData) |
| If Event.source=MyCanvas And Event.ID=EVENT_GADGETPAINT |
| UpdateCanvas() |
| Return Null |
| Return tData |
| SuperStrict Local x:Int=(GadgetWidth(Desktop())-400)/2 Local y:Int=(GadgetHeight(Desktop())-400)/2 Local MyWindow:TGadget=CreateWindow("EventHook Example", x,y,400,400) Global MyCanvas:TGadget=CreateCanvas(0,0,380,360,MyWindow) Local SmallWindow:TGadget=CreateWindow("Move Me", x+125, y+150, 150, 100, MyWindow, WINDOW_TITLEBAR) AddHook EmitEventHook, MyHook AddHook EmitEventHook, SecondHook Repeat WaitEvent() Select EventID() Case EVENT_WINDOWCLOSE End Case EVENT_GADGETPAINT UpDateCanvas() End Select Forever End Function SecondHook:Object(iId:Int,tData:Object,tContext:Object) Local Event:TEvent=TEvent(tData) If event=Null Return Null If Event.source=MyCanvas And Event.ID=EVENT_MOUSEDOWN Notify "Click Me" Return Null EndIf Return tData End Function Function MyHook:Object(iId:Int,tData:Object,tContext:Object) Local Event:TEvent=TEvent(tData) If Event.source=MyCanvas And Event.ID=EVENT_GADGETPAINT UpdateCanvas() Return Null EndIf Return tData End Function Function UpdateCanvas:Int() SetGraphics CanvasGraphics(MyCanvas) Cls SetColor Rnd(255),Rnd(255),Rnd(255) DrawRect 10,10,100,150 Flip End Function |
| Function SecondHook:Object(iId:Int,tData:Object,tContext:Object) Local Event:TEvent=TEvent(tData) If event=Null Return Null |
| If Event.source=MyCanvas And Event.ID=EVENT_MOUSEDOWN Notify "Click Me" Return Null EndIf |