Events and Hooks Help
BlitzMax Forums/BlitzMax Programming/Events and Hooks Help
| ||
Ok, so my idea here is to be able to have the program automatically call a function every time a button is pressed, without me needing to type:If EventID() = EVENT_GADGETACTION Then blah blah blah... So my idea was to have it work like Visual Basic with it's Handle function Private Sub button1_click(...) Handles button1.Click The only problem being I have absolutely no idea how to do this. I experimented a little with the AddHook and EmitEventHook stuff but it still makes no sense to me. Could someone please show me a way to do this? |
| ||
You could extend the TGadget type and in your extension, place a few function pointers:Type MyCoolGadget Extends TGadget Field onClick() Field onMouseOver() EndType The problem is that you have to make your own functions for creating gadgets so that they return "MyCoolGadget" instead of "TGadget". You could also use the "extra" field to insert your new type in there. Then you need to specify those functions after creation: Local btn:MyCoolGadget = CreateCoolButton(blah blah) btn.onClick = MyCoolClickFunction btn.onMouseOver = MyAwesomeMouseOverFunction Last, but not least, you have to write your code for handling this: If EventID() = EVENT_GADGETACTION Then MyCoolGadget(EventSource()).onClick() 'or the other option MyCoolGadget(EventSource().extra).onClick() Endif Hope this helps ;) |